Grokking Concurrency in Go
0% completed
Deadlocks
Two bank transfers run at the same time: one moves money from Alice to Bob, the other from Bob to Alice. Each transfer locks the account it takes money from, waits a moment, and then locks the account it pays into. When main waits for both transfers with a sync.WaitGroup, the program stops within a few milliseconds and the runtime prints fatal error: all goroutines are asleep - deadlock!.
Now keep both transfers exactly as they are and change only how main waits: it gives up after 500 ms and prints a message
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%