Skip to content

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Go Concurrency Programming Learning Notes

A systematic Go concurrency programming learning project, from basics to advanced, including theory, practice, and real-world projects.

Project Overview

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

Project Structure

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

📊 Current Progress

✅ 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

Quick Start

1. Start Learning (Recommended)

# Start learning directly
cd 01-basics/goroutines
cat README.md              # Read theory
go run basic.go            # Run examples
go test -v                 # Run tests

2. Start with Spinlock

The 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 -v

3. Read Documentation

Start with core concepts:

cat docs/concepts.md        # Understand concurrency basics
cat docs/pitfalls.md        # Learn common pitfalls
cat docs/best-practices.md  # Learn best practices

Learning Path

Beginner (1-2 weeks)

Goal: Master Go concurrency basics

  1. Learn content in 01-basics/

    • Creating and managing Goroutines
    • Various uses of Channels
    • Select multiplexing
    • WaitGroup synchronization
  2. Read docs/concepts.md

    • Understand concurrency vs parallelism
    • Understand CSP model
    • Understand Go memory model

Intermediate (2-3 weeks)

Goal: Master concurrency patterns and sync primitives

  1. Learn concurrency patterns in 02-patterns/

    • Pipeline pattern
    • Fan-out/Fan-in
    • Worker Pool
    • Cancellation and timeout
  2. Learn 03-sync-primitives/

    • Mutex and RWMutex
    • ⭐ Spinlock implementation (completed)
    • Atomic operations
    • sync.Once and sync.Cond
  3. Read docs/pitfalls.md

    • Avoid common mistakes
    • Use race detector

Advanced (2-3 weeks)

Goal: Master advanced techniques and optimization

  1. Learn advanced topics in 04-advanced/

    • Deep dive into Context
    • Rate limiting implementation
    • Semaphore usage
    • Concurrent-safe data structures
  2. Read docs/best-practices.md

    • Design principles
    • Performance optimization
    • Testing strategies

Real-world (Ongoing)

Goal: Apply knowledge

Choose projects from 05-real-world/:

  1. Web Crawler - Comprehensive concurrency patterns
  2. Downloader - File I/O concurrency control
  3. Task Scheduler - Complex concurrent system design
  4. Data Processor - Stream data processing

Highlights

⭐ Complete Spinlock Implementation

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

Testing and Validation

Run Tests

# Run all tests
go test ./...

# Race detection
go test -race ./...

# Run benchmarks
go test -bench=. -benchmem ./...

Spinlock Performance Testing

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

Learning Resources

Official Documentation

Recommended Books

  • "Concurrency in Go" - Katherine Cox-Buday
  • "The Go Programming Language" - Alan Donovan & Brian Kernighan
  • "The Art of Multiprocessor Programming" - Maurice Herlihy

Video Tutorials

Recommended Tools

Essential Tools

# 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

Optional Tools

Contributing

Contributions welcome! If you want to add new examples or improve existing content:

  1. Fork this project
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add some amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Roadmap

  • 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

License

This project is licensed under the MIT License - see LICENSE file for details

Acknowledgments

Thanks to all developers and authors who have contributed to Go concurrency programming.


Quick Links

Start your Go concurrency programming journey! 🚀

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages