go-concurrency-patterns
하는 일
이 도구는 Go 프로그램에서 여러 일을 동시에 하는 고급 방법을 이해하고 사용하도록 돕습니다. '고루틴'(함께 실행되는 작은 작업)과 '채널'(작업들 사이의 통신 통로)을 쓰는 방법을 가르칩니다.
사용하는 경우
- ✓여러 일을 동시에 해야 하는 Go 프로그램을 만들 때.
- ✓작업이 함께 효율적으로 일하도록 정리할 때(예: '워커 풀').
- ✓프로그램이 충돌하거나 동시성 오류가 나는 이유를 알아내려고 할 때.
스킬 링크
https://github.com/wshobson/agents/blob/main/plugins/systems-programming/skills/go-concurrency-patterns/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“Go 프로그램의 두 부분이 동시에 실행되고 정보를 안전하게 주고받도록 하려면 어떻게 해야 하나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
Go에서 동시성의 기본 구성 요소인 '고루틴'과 '채널'을 설명하고, 통신과 동기화에 쓰는 예시를 보여 줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Go Concurrency Patterns
Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management.
When to Use This Skill
- Building concurrent Go applications
- Implementing worker pools and pipelines
- Managing goroutine lifecycles
- Using channels for communication
- Debugging race conditions
- Implementing graceful shutdown
Core Concepts
1. Go Concurrency Primitives
| Primitive | Purpose |
|---|---|
goroutine |
Lightweight concurrent execution |
channel |
Communication between goroutines |
select |
Multiplex channel operations |
sync.Mutex |
Mutual exclusion |
sync.WaitGroup |
Wait for goroutines to complete |
context.Context |
Cancellation and deadlines |
2. Go Concurrency Mantra
Don't communicate by sharing memory;
share memory by communicating.
Quick Start
package main
import (
"context"
"fmt"
"sync"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
results := make(chan string, 10)
var wg sync.WaitGroup
// Spawn workers
for i := 0; i < 3; i++ {
wg.Add(1)
go worker(ctx, i, results, &wg)
}
// Close results when done
go func() {
wg.Wait()
close(results)
}()
// Collect results
for result := range results {
fmt.Println(result)
}
}
func worker(ctx context.Context, id int, results chan<- string, wg *sync.WaitGroup) {
defer wg.Done()
select {
case <-ctx.Done():
return
case results <- fmt.Sprintf("Worker %d done", id):
}
}
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
Do's
- Use context - For cancellation and deadlines
- Close channels - From sender side only
- Use errgroup - For concurrent operations with errors
- Buffer channels - When you know the count
- Prefer channels - Over mutexes when possible
Don'ts
- Don't leak goroutines - Always have exit path
- Don't close from receiver - Causes panic
- Don't use shared memory - Unless necessary
- Don't ignore context cancellation - Check ctx.Done()
- Don't use time.Sleep for sync - Use proper primitives
자주 묻는 질문
'고루틴'이란 무엇인가요?
프로그램의 다른 부분과 간섭하지 않고 동시에 실행될 수 있는 함수와 같습니다.
'채널'은 무엇에 쓰나요?
고루틴들이 서로 메시지를 안전하게 주고받을 수 있는 파이프와 같습니다.
'메모리를 공유해서 통신하지 말고, 통신해서 메모리를 공유하라'는 무슨 뜻인가요?
여러 프로그램 부분이 같은 데이터에 동시에 접근하는 것(오류를 일으킬 수 있음)을 피하라는 조언입니다. 대신 '채널'을 사용해 데이터를 주고받으세요.
상세 정보
작성자의 원본 설명
Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions.
repo: wshobson/agents
인기도
- GitHub 스타
- 41k
- 순위
- #6798
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
screen-reader-testing
41k에이전트가 스크린 리더로 웹사이트를 테스트해 접근성을 확인하도록 돕습니다.
wcag-audit-patterns
41k에이전트가 WCAG 지침에 따라 웹사이트의 접근성을 감사하고 문제를 고치도록 돕습니다.
multi-reviewer-patterns
41k에이전트가 병렬 코드 리뷰를 조율하고, 중복된 발견 사항을 정리하며, 보고서를 통합하도록 돕습니다.
parallel-debugging
41k에이전트가 병렬 조사와 근본 원인 분석으로 복잡한 문제를 디버그하도록 돕습니다.