GopherCon 2017: Understanding Channels | Kavya Joshi

Added:

Channel Basics
Underlying Structure
Send and Receive
Blocking Behavior
Resumption Setup
Direct Handoff
Reverse Scenario
Design Tradeoffs

Channel Basics

0:01
Playing Section
  • 1

    Introduces channels as a core Go concurrency primitive for goroutine communication.

  • 2

    Demonstrates a task queue model using a buffered channel and multiple workers.

  • 3

    Highlights channel properties like goroutine safety, FIFO ordering, and blocking behavior.

Basic proficiency in Go, specifically implementing concurrent programs using Goroutines and the fundamental syntax of channels.
Understanding of operating system threading models, user-space scheduling (green threads), and basic synchronization primitives like mutexes.
Familiarity with standard computer science data structures, specifically ring buffers, circular queues, and wait queues.
Fundamental concepts of memory allocation, including the distinction between stack and heap memory.
Deep dive into the Go runtime's G-M-P (Goroutine, Machine, Processor) scheduling model and its work-stealing algorithm.
Advanced concurrent design patterns in Go, such as fan-in/fan-out, worker pools, pipelines, and context-based cancellation.
Profiling and debugging Go concurrency issues using the Go execution tracer, pprof, and the race detector.
Evaluating performance trade-offs between lock-free atomic operations, standard sync primitives (Mutexes), and channel-based communication.
129.1K views3.9Klikes21:45@GopherAcademyOriginal Release: 2017-07-24

Go channels are implemented as hchan structs containing a circular buffer, send/receive indexes, and a mutex, enabling goroutine-safe FIFO communication; when a goroutine blocks on a full channel send or empty channel receive, it calls go_park to the runtime scheduler, which changes its state to waiting and frees the OS thread, while the scheduler manages goroutines through an M:N model where M represents OS threads, N represents goroutines, and P holds the scheduling context with run queues, allowing efficient context switching without blocking expensive OS threads.