← blog
#10ConcurrencyB3

Channels vs mutexes

Channels for coordination: passing data around. Mutexes for state: struct fields, cache maps, counters.

Keep the locked section small. Do not do network I/O, disk writes or channel sends while you hold a lock. Every other goroutine that needs the lock must wait until you release it.