go-concurrency
Skill7 starsChanged 3 days agoApache-2.0View on GitHub
Use when writing concurrent Go code with goroutines, channels, mutexes, timers, or tickers; parallelizing work; fixing data races; or protecting shared state. Context cancellation belongs to go-context.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- lengrufeng2008/dsh-skill-librarytheir own version, first seen Nov 15, 2026
- inference-gateway/skillstheir own version, first seen Nov 12, 2026
- Lu1sDV/skillsmdtheir own version, first seen Nov 1, 2026
- hishamkaram/claude-code-routertheir own version, first seen Oct 27, 2026
- AllThingsSmitty/proven-skillstheir own version, first seen Oct 6, 2026
- Dankosik/golang-backend-skillstheir own version, first seen Sep 8, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- hishamkaram/claude-code-router★ 12same name
- wpank/ai★ 11same name
- inference-gateway/skills★ 3same name
- CasLubbers/code-design-skills★ 2same name
- Lu1sDV/skillsmd★ 2same name
- AllThingsSmitty/proven-skills★ 1same name
- Cadasto/go-coding-plugin★ 0same name
- Dankosik/golang-backend-skills★ 0same name
- lengrufeng2008/dsh-skill-library★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- go-code-refactorSkill
- go-code-reviewSkill
- go-codeSkill
- go-contextSkill
- go-databaseSkill
- go-data-structuresSkill
- go-defensiveSkill
- go-documentationSkill
- go-error-handlingSkill
- go-functionsSkill
- go-genericsSkill
- go-httpSkill
- go-interfacesSkill
- go-lintingSkill
- go-loggingSkill
- go-namingSkill
- go-packagesSkill
- go-performanceSkill
- go-resilienceSkill
- go-securitySkill
- go-style-coreSkill
- go-testingSkill
- go-troubleshootingSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 118
Use atomic.Bool, atomic.Int64, etc.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Concurrency
Compatibility: Baseline Go 1.27 (see COMPATIBILITY.md).
sync.WaitGroup.Goandtesting/synctestrequire Go 1.25+; typed atomics (atomic.Bool) are stdlib since Go 1.19; thegoroutineleakprofile follows the toolchain that builds the binary, not thegodirective (Go 1.27 toolchain).
Resource Routing
references/GOROUTINE-PATTERNS.md- Read when starting, stopping, or waiting for goroutines.references/SYNC-PRIMITIVES.md- Read when choosing between mutexes, atomics, channels, and once-like primitives, or when code stops, resets, or drains a timer.references/BUFFER-POOLING.md- Read when considering channel-backed or sync.Pool-style reuse.references/ADVANCED-PATTERNS.md- Read for bounded errgroup work, cooperative cancellation, request/reply channels, and CPU-bound parallelization.
Goroutine Lifetimes
Normative: When you spawn goroutines, make it clear when or whether they exit.
The GC will not terminate a blocked goroutine even if no other goroutine holds a reference to the channel.
Core Rules
- Every goroutine needs a stop mechanism — a predictable end time, a cancellation signal, or both
- Code must be able to wait for the goroutine to finish
- No goroutines in
init()— expose lifecycle methods (Close,Stop,Shutdown) instead - Keep synchronization scoped — constrain to function scope, factor logic into synchronous functions
- Bound fan-out —
errgroup.Group.SetLimit(n)whengo.modalready requiresgolang.org/x/sync, otherwise a buffered-channel semaphore withwg.Go; never one goroutine per element of an unbounded input
// Good: a fixed pair of tasks, both joined before returning
var wg sync.WaitGroup
wg.Go(func() { process(ctx, first) })
wg.Go(func() { process(ctx, second) })
wg.Wait()process must honor ctx and must not panic; WaitGroup.Go does not propagate
errors or cancel tasks. For variable-size input or sibling cancellation on
error, use the bounded errgroup pattern in references/ADVANCED-PATTERNS.md.
Test for leaks with synctest.Test (Go 1.25+), which fails when a goroutine
started in its bubble is still durably blocked once the test function
returns: on a channel made in the bubble, sync.Cond.Wait, a bubble
WaitGroup.Wait, or time.Sleep. A goroutine stuck in Mutex.Lock, in I/O,
or on a channel made outside the bubble makes Test hang until -timeout
instead. Outside a bubble, read the goroutineleak profile in the tested
process — Go 1.27 toolchain (1.26 needs GOEXPERIMENT=goroutineleakprofile);
DIAGNOSTIC-TOOLS.md
has the nil-guarded form and what it misses. Keep
go.uber.org/goleak where the project
already uses it; do not add the module for code a bubble can host.
Share by Communicating
"Do not communicate by sharing memory; instead, share memory by communicating."
Pick the primitive by the shape of the problem, not by preference:
Do you need a goroutine at all?
├─ No — a return value or a synchronous call does it → no goroutine, no channel
└─ Yes
├─ Handing a value or ownership to another goroutine → channel
├─ Protecting shared state (cache, counter, map) → sync.Mutex / RWMutex; atomic.* for one word
├─ Fan-out that must be bounded → errgroup SetLimit (x/sync in go.mod) or wg.Go + semaphore
└─ Both fit → the one with fewer linesA goroutine whose caller immediately waits for it is a function call with extra steps — it is on the hunt list in go-code-refactor.
Synchronous Functions
Normative: Prefer synchronous functions over asynchronous ones.
Mutexes
Don't embed mutexes — use a named mu field to keep Lock/Unlock as
implementation details, not exported API.
No recursive RLock. A method holding mu.RLock never calls one that
takes mu.RLock again: once a writer waits in Lock, the second RLock
blocks behind it and neither proceeds. Split the body into an unlocked
…Locked variant that both public methods call.
Channel Direction
Normative: Specify channel direction where possible.
Channel Size: One or None
Channels should have size zero (unbuffered) or one. Any other size requires justification for:
- How the size was determined
- What prevents the channel from filling under load
- What happens when writers block
A semaphore channel (make(chan struct{}, n) for the bounded fan-out above)
is not a buffer: n is the concurrency limit, and that is its justification.
Atomic Operations
Use atomic.Bool, atomic.Int64, etc. from the standard sync/atomic package
for type-safe atomic operations. Keep go.uber.org/atomic when already
used by the project or when a required operation is absent from the standard
library.
Related Skills
- go-resilience: bulkhead admission, backpressure, rate scope, recovery budgets.
- go-context: deriving contexts, deadlines, cancel causes, request-scoped values.
- go-error-handling: errors from goroutines, errgroup.
- go-defensive: shared state at API boundaries, defer for cleanup.
- go-interfaces: receiver types for types holding sync primitives.
- go-troubleshooting: goroutine dumps, race reports, the symptom catalog when the cause is unknown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

