在 Manus 中运行任何 Skill
一键导入
一键导入
一键在 Manus 中运行任何 Skill
开始使用go-sync-primitives
星标3
分支0
更新时间2025年12月18日 03:03
sync.WaitGroup and sync.Mutex patterns
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
sync.WaitGroup and sync.Mutex patterns
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Handle hook scripts and paths for plugin packaging
Package claudefiles components into a valid Claude Code plugin
Package language-specific subsets of claudefiles
Plugin validation errors and fixes
Common channel patterns and idioms
Context cancellation patterns for graceful shutdown
| name | go-sync-primitives |
| description | sync.WaitGroup and sync.Mutex patterns |
func processBatch(items []string) {
var wg sync.WaitGroup
for _, item := range items {
wg.Add(1) // BEFORE launching goroutine
go func(item string) {
defer wg.Done()
process(item)
}(item)
}
wg.Wait() // Block until all done
}
func processBatch(items []string) {
var wg sync.WaitGroup
for _, item := range items {
go func(item string) {
wg.Add(1) // WRONG: race condition
defer wg.Done()
process(item)
}(item)
}
wg.Wait() // May return early
}
func processBatch(items []string) {
var wg sync.WaitGroup
for _, item := range items {
wg.Add(1)
go func() {
defer wg.Done()
process(item) // WRONG: captures loop variable
}()
}
wg.Wait()
}
type Counter struct {
mu sync.Mutex
value int
}
func (c *Counter) Increment() {
c.mu.Lock()
defer c.mu.Unlock()
c.value++
}
func (c *Counter) Value() int {
c.mu.Lock()
defer c.mu.Unlock()
return c.value
}
type Counter struct {
mu sync.Mutex
value int
}
func (c *Counter) Increment() {
c.mu.Lock()
c.value++ // What if panic happens?
c.mu.Unlock()
}
func (c *Counter) Value() int {
return c.value // WRONG: race condition
}
type Cache struct {
mu sync.RWMutex
data map[string]string
}
func (c *Cache) Get(key string) (string, bool) {
c.mu.RLock() // Multiple readers OK
defer c.mu.RUnlock()
val, ok := c.data[key]
return val, ok
}
func (c *Cache) Set(key, value string) {
c.mu.Lock() // Exclusive writer
defer c.mu.Unlock()
c.data[key] = value
}
Add() before go statementdefer wg.Done()Add(n) can count multiple goroutinesdefer mu.Unlock()var (
instance *Singleton
once sync.Once
)
func GetInstance() *Singleton {
once.Do(func() {
instance = &Singleton{}
})
return instance
}
go test -race ./...
go run -race main.go