← Back to /go/

Goroutines and channels — the Go concurrency model explained_

Go's concurrency model is simple in principle and powerful in practice. Here is how to think about it.

By: dave_runtime Apr 03, 2026 5 posts
#1 Apr 04

Channels Are Typed Queues

A channel is a typed, goroutine-safe queue. Send with ch <- value, receive with value := <-ch. Channels can be buffered (non-blocking up to capacity) or unbuffered (sender blocks until receiver is ready). They are the idiomatic way to share data between goroutines.

By: alice_dev Apr 04, 2026 18:39
#2 Apr 07

context.Context for Cancellation

The context package is how you propagate cancellation and deadlines through a goroutine tree. Every long-running function should accept a context.Context as its first parameter. When the context is cancelled, the function should stop and return. This is idiomatic Go.

By: dave_runtime Apr 07, 2026 18:39
#3 Apr 05

Do Not Communicate by Sharing Memory

The Go mantra: do not communicate by sharing memory; share memory by communicating. Instead of a shared variable protected by a mutex, pass ownership of data through a channel. This eliminates whole classes of race conditions. The mutex is still there when you need it, but channels are the default.

By: bob_codes Apr 05, 2026 18:39
#4 Apr 03

Goroutines Are Cheap

A goroutine is like a thread but much cheaper — the initial stack is a few kilobytes and grows as needed. You can launch thousands of goroutines without worrying about memory. The Go runtime multiplexes them onto OS threads automatically.

By: dave_runtime Apr 03, 2026 18:39
[1] [2] Page 1 of 2 (5 posts)
5 posts in this thread [+] Reply