/go-concurrency

Master Go concurrency, from fundamentals to advanced patterns

Primary LanguageGo

Go Concurrency: From Basics to Advanced

This repo is my personal knowledge base on goroutines and concurrency in Go. It includes notes and examples to help quickly understand these concepts and build concurrent programs.

πŸ“‹ Topics Covered

1️⃣ Concepts

  • πŸ“˜ Fundamentals: Processes, Threads, OS concepts.
  • βš™οΈ Go Scheduler: How the Go runtime manages goroutines.
  • πŸ” Comparison: Concurrency, parallelism, async programming.

2️⃣ Basics

  • πŸŒ€ Goroutines: Lightweight threads in Go.
  • ⏳ WaitGroup: Coordinating goroutine completion.
  • πŸ“‘ Channels: Communication between goroutines.

3️⃣ Sync Tools

  • πŸ”’ Mutex: Mutual exclusion for critical sections.
  • ⚑ Atomic: Low-level atomic operations.
  • πŸ“£ Cond: Signaling between goroutines.
  • πŸ”‚ Once: Ensuring a task runs only once.
  • 🏊 Pool: Reusable object pools.
  • πŸ—ΊοΈ Map: Concurrent-safe maps.

4️⃣ Advanced

  • 🌐 Context: Managing deadlines, cancellations.
  • πŸ“¬ Select Statement: Handling multiple channel operations.
  • πŸ›‘ Deadlock: Detecting and avoiding deadlocks.
  • ⚠️ Data Race: Understanding and fixing data races.

5️⃣ Patterns

  • β›” Cancellation: Graceful task cancellation.
  • ➑️ Fan-out: Distributing tasks to workers.
  • ⬅️ Fan-in: Aggregating results from workers.
  • πŸ”„ Fan-out & Fan-in: Combining fan-out and fan-in.
  • πŸ”— Pipeline: Processing data through stages.
  • 🚦 Semaphore: Controlling access to limited resources or tasks.
  • πŸ“‘ Pub/Sub: Message broadcasting between publishers and subscribers.

πŸ’‘ Feel free to explore, contribute, and improve this knowledge base!