Skip to content
Agentmart
Submit a tool

zig-concurrency

Zig 并发编程技能。涉及 std.Thread 的线程创建、同步原语(Mutex、RwLock、Condition、Semaphore、WaitGroup)、线程池和原子操作。在需要多线程或并行计算时调用。

Skill by Yabuku-xD

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/yabuku-xd-zig-concurrency

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Zig 并发编程技能。涉及 std.Thread 的线程创建、同步原语(Mutex、RwLock、Condition、Semaphore、WaitGroup)、线程池和原子操作。在需要多线程或并行计算时调用。

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/zig-concurrency

What's inside

Skill name
zig-concurrency
Description
Zig 并发编程技能。涉及 std.Thread 的线程创建、同步原语(Mutex、RwLock、Condition、Semaphore、WaitGroup)、线程池和原子操作。在需要多线程或并行计算时调用。
License
MIT
Instructions
271 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Zig 并发编程

> 基于 std.Thread 和 std.atomic 的并发原语(Zig 0.16.0)。

## Capability Boundaries

### ✅ 强项
1. 线程创建与管理(spawn、join、detach)
2. 同步原语(Mutex、RwLock、Condition、Semaphore、ResetEvent、WaitGroup)
3. 线程池(Thread.Pool)用于并行任务
4. 原子操作(std.atomic.Value)
5. 常见并发模式(生产者-消费者、工作队列)

### ⚠️ 前置要求
1. 确认 Zig 版本(`zig version`)
2. 理解基本并发概念(竞态条件、死锁)

### ❌ 不适用范围
1. 异步 I/O → 使用 `zig-http` 或 `zig-0.16` 的 std.Io
2. 非并发场景 → 使用 `zig-0.16` 技能

## 何时使用

- "多线程处理数据"
- "并行执行多个任务"
- "线程安全的共享状态"

## Data Privacy

本技能不收集、存储或传输任何用户数据。

## Workflow

步骤 1. **识别并发需求** — CPU 密集 / I/O 等待 / 并行计算?
步骤 2. **选择原语** — 线程 / 线程池 / 原子操作?
步骤 3. **实现同步** — Mutex / RwLock / WaitGroup
步骤 4. **测试正确性** — 竞态条件、死锁检查

## 模块总览

```zig
std.Thread                  // 线程创建与管理
std.Thread.Mutex            // 互斥锁
std.Thread.Mutex.Recursive  // 可重入互斥锁
std.Thread.RwLock           // 读写锁
std.Thread.Condition        // 条件变量
std.Thread.Semaphore        // 计数信号量
std.Thread.ResetEvent       // 布尔事件标志(阻塞式)
std.Thread.WaitGroup        // 等待多任务完成
std.Thread.Pool             // 线程池
std.Thread.Futex            // 底层 futex(高级)
std.atomic.Value(T)         // 原子类型包装
```

## 线程创建

### 基本线程
```zig
fn worker(id: usize) void {
    std.debug.print("Worker {d}\n", .{id});
}

const thread = try std.Thread.spawn(.{}, worker, .{42});
thread.join();  // 等待完成
```

### 带分配器配置
```zig
const thread = try std.Thread.spawn(.{ .allocator = allocator }, worker, .{42});
defer thread.join();
```

### 分离线程(不 join)
```zig
const thread = try std.Thread.spawn(.{}, worker, .{1});
thread.detach();  // 线程自动清理
```

## 同步原语

### Mutex(互斥锁)
```zig
var mutex: std.Thread.Mutex = .{};
var shared: i32 = 0;

fn increment() void {
    mutex.lock();
    defer mutex.unlock();
    shared += 1;
}
```

### RwLock(读写锁)
```zig
var rwlock: std.Thread.RwLock = .{};
var data: i32 = 0;

fn reader() void {
    rwlock.lockShared();
    defer rwlock.unlockShared();
    _ = data;  // 可并发读
}

fn writer() void {
    rwlock.lock();
    defer rwlock.unlock();
    data += 1;  // 独占写
}
```

### Condition(条件变量)
```zig
var mutex: std.Thread.Mutex = .{};
var cond: std.Thread.Condition = .{};
var ready: bool = false;

fn waiter() void {
    mutex.lock();
    defer mutex.unlock();

From Yabuku-xD/omfx, MIT.

More from Yabuku-xD/omfx

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Aug 24, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Yabuku-xD

Cite this page

zig-concurrency skill. Agent Mart. https://agentmart.dev/skills/yabuku-xd-zig-concurrency (last updated 2026-10-24)