A systematic Go concurrency programming learning project, from basics to advanced, including theory, practice, and real-world projects.
This project aims to provide a complete Go concurrency programming learning path, covering:
- Core concepts and theoretical foundations
- Various concurrency primitives
- Classic concurrency patterns
- Low-level implementations like spinlocks
- Real-world project practice
go-concurrency-notes/
├── 01-basics/ # Concurrency Basics
│ ├── goroutines/ # Goroutine Fundamentals
│ ├── channels/ # Channel Fundamentals
│ ├── select/ # Select Statement
│ └── waitgroup/ # WaitGroup Usage
│
├── 02-patterns/ # Concurrency Patterns
│ ├── pipeline/ # Pipeline Pattern
│ ├── fan-out-fan-in/ # Fan-out/Fan-in Pattern
│ ├── worker-pool/ # Worker Pool Pattern
│ ├── cancellation/ # Cancellation and Timeout
│ └── error-handling/ # Error Handling
│
├── 03-sync-primitives/ # Synchronization Primitives
│ ├── mutex/ # Mutex/RWMutex
│ ├── spinlock/ # ⭐ Spinlock Implementation & Analysis
│ ├── atomic/ # Atomic Operations
│ ├── once/ # sync.Once
│ └── cond/ # sync.Cond
│
├── 04-advanced/ # Advanced Topics
│ ├── context/ # Context Deep Dive
│ ├── rate-limiting/ # Rate Limiting
│ ├── semaphore/ # Semaphore
│ └── concurrent-ds/ # Concurrent Data Structures
│
├── 05-real-world/ # Real-world Projects
│ ├── web-crawler/ # Concurrent Web Crawler
│ ├── downloader/ # Concurrent Downloader
│ ├── task-scheduler/ # Task Scheduler
│ └── data-processor/ # Real-time Data Processor
│
├── 06-go-fundamentals/ # Go Fundamentals (Interview)
│ ├── slice-internals.md # Slice Internals
│ ├── map-internals.md # Map Internals
│ ├── interface-internals.md # Interface Internals
│ ├── defer-panic-recover.md # Defer/Panic/Recover
│ ├── gc-and-memory.md # GC & Memory Management
│ ├── struct-and-method.md # Struct & Methods
│ ├── string-rune-byte.md # String/Rune/Byte
│ ├── error-handling.md # Error Handling
│ ├── init-and-execution-order.md # Init & Execution Order
│ ├── generics.md # Generics (Go 1.18+)
│ └── common-interview-qa.md # Common Interview Q&A
│
└── docs/ # Documentation
├── concepts.md # Core Concepts Summary
├── pitfalls.md # Common Pitfalls
└── best-practices.md # Best Practices
✅ 01-basics (100%) - Complete basic chapters ✅ 02-patterns (100%) - Concurrency patterns ✅ 03-sync-primitives (20%) - Spinlock completed ✅ docs (100%) - Core documentation ✅ 06-go-fundamentals (100%) - Go fundamentals & interview topics ⏳ 04-advanced (0%) - To be created ⏳ 05-real-world (0%) - To be created
👉 See detailed learning path: LEARNING_PATH.md
# Start learning directly
cd 01-basics/goroutines
cat README.md # Read theory
go run basic.go # Run examples
go test -v # Run testsThe spinlock chapter is fully implemented, perfect for understanding low-level concurrency primitives:
cd 03-sync-primitives/spinlock
# View learning guide
cat README.md
# Run examples
go run example.go
# Run benchmarks
go test -bench=. -benchmem
# Run correctness tests
go test -vStart with core concepts:
cat docs/concepts.md # Understand concurrency basics
cat docs/pitfalls.md # Learn common pitfalls
cat docs/best-practices.md # Learn best practicesGoal: Master Go concurrency basics
-
Learn content in
01-basics/- Creating and managing Goroutines
- Various uses of Channels
- Select multiplexing
- WaitGroup synchronization
-
Read
docs/concepts.md- Understand concurrency vs parallelism
- Understand CSP model
- Understand Go memory model
Goal: Master concurrency patterns and sync primitives
-
Learn concurrency patterns in
02-patterns/- Pipeline pattern
- Fan-out/Fan-in
- Worker Pool
- Cancellation and timeout
-
Learn
03-sync-primitives/- Mutex and RWMutex
- ⭐ Spinlock implementation (completed)
- Atomic operations
- sync.Once and sync.Cond
-
Read
docs/pitfalls.md- Avoid common mistakes
- Use race detector
Goal: Master advanced techniques and optimization
-
Learn advanced topics in
04-advanced/- Deep dive into Context
- Rate limiting implementation
- Semaphore usage
- Concurrent-safe data structures
-
Read
docs/best-practices.md- Design principles
- Performance optimization
- Testing strategies
Goal: Apply knowledge
Choose projects from 05-real-world/:
- Web Crawler - Comprehensive concurrency patterns
- Downloader - File I/O concurrency control
- Task Scheduler - Complex concurrent system design
- Data Processor - Stream data processing
The 03-sync-primitives/spinlock/ directory contains:
-
7 Spinlock Implementations
- TAS (Test-and-Set)
- TTAS (Test-and-Test-and-Set)
- TTAS with Yield
- Backoff Spinlock
- Ticket Lock
- MCS Lock
- Adaptive Lock
-
Comprehensive Performance Testing
- Comparison with sync.Mutex
- Testing under different contention scenarios
- Scalability testing
-
Detailed Learning Notes
- Analysis of each implementation
- CPU cache effects explanation
- Performance data and recommendations
# Run all tests
go test ./...
# Race detection
go test -race ./...
# Run benchmarks
go test -bench=. -benchmem ./...cd 03-sync-primitives/spinlock
# Benchmarks
go test -bench=. -benchtime=5s
# Comparison tests
go test -bench=TASLock
go test -bench=TTASLock
go test -bench=Mutex
# CPU profiling
go test -bench=. -cpuprofile=cpu.prof
go tool pprof cpu.prof- "Concurrency in Go" - Katherine Cox-Buday
- "The Go Programming Language" - Alan Donovan & Brian Kernighan
- "The Art of Multiprocessor Programming" - Maurice Herlihy
# Race detection
go test -race
# Static analysis
go vet ./...
# Code linting
golangci-lint run
# Performance profiling
go test -bench=. -cpuprofile=cpu.prof
go tool pprof cpu.prof- staticcheck - Advanced static analysis
- go-deadlock - Deadlock detection
- pprof - Performance profiling
Contributions welcome! If you want to add new examples or improve existing content:
- Fork this project
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add some amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
- Complete spinlock implementation
- Basic chapter example code
- Concurrency pattern example code
- Go fundamentals interview topics
- Other sync primitive examples
- Advanced topic implementation
- Real-world projects
- Video tutorials
- Blog articles
This project is licensed under the MIT License - see LICENSE file for details
Thanks to all developers and authors who have contributed to Go concurrency programming.
Start your Go concurrency programming journey! 🚀