go-concurrency

Guide concurrent Go code with goroutines, channels, and sync primitives.

Updated Dec 31, 2025
One-click install
npx skills add https://github.com/victorzhuk/go-ent --skill go-concurrency-victorzhuk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-concurrency
Source: https://github.com/victorzhuk/go-ent/tree/main/pkg/skills/go/go-concurrency
Command: npx skills add https://github.com/victorzhuk/go-ent --skill go-concurrency-victorzhuk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write safe, efficient, and deadlock-free concurrent Go programs by providing expert guidance on goroutines, channels, and synchronization primitives.

Core Features & Use Cases

  • Goroutine Management: Learn to properly manage goroutine lifecycles with context cancellation.
  • Channel Patterns: Understand buffered vs. unbuffered channels, close semantics, and select statements.
  • Synchronization: Master mutexes, WaitGroups, and atomic operations to prevent race conditions.
  • Concurrency Patterns: Implement worker pools, pipelines, fan-out/fan-in, and more.
  • Use Case: Debugging a suspected goroutine leak by ensuring all spawned goroutines have a clear exit strategy tied to context cancellation.

Quick Start

Explain how to implement a worker pool using errgroup to process a slice of items concurrently.

Frequently Asked Questions about go-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent goroutine leaks in Go concurrent programs?

Prevent goroutine leaks by managing goroutine lifecycles with context cancellation, ensuring all spawned goroutines have a clear exit strategy tied to context cancellation. This approach avoids orphaned goroutines consuming memory and CPU resources indefinitely.

What is the best way to process a slice of items concurrently in Go?

Process items concurrently by implementing a worker pool using `errgroup` to manage goroutines. This pattern controls concurrency levels, handles errors gracefully, and waits for all processing tasks to complete successfully before exiting.

How do buffered and unbuffered channels affect Go concurrency patterns?

Buffered and unbuffered channels affect synchronization behavior: unbuffered channels block until both sender and receiver are ready, while buffered channels block only when full. Proper close semantics and select statements ensure safe channel communication.

When should I use sync.Mutex vs atomic operations in Go?

Use sync.Mutex for protecting complex shared state across multiple statements, and use atomic operations for simple, single-variable updates like counters. Both synchronization primitives prevent race conditions, but atomic operations carry less overhead.

Why does my Go concurrent code deadlock when using WaitGroup?

Deadlocks with WaitGroup often occur when goroutines wait on channel operations that never complete, or when WaitGroup Add calls happen after Wait. Proper synchronization and clear exit strategies tied to context cancellation resolve these blocking issues.

Can I implement fan-out fan-in pipelines using Go channels?

Yes, implement fan-out/fan-in pipelines by distributing work across multiple goroutines and merging results through channels. This concurrency pattern parallelizes processing stages, improving throughput for computationally intensive workflows.