6.824 Lecture 5 - Go, Threads, and Raft
- https://www.youtube.com/watch?v=UzzcUS2OHqo
- Req: The Go Memory Model
- The first section was fairly basic, and BookConcurrency in Go covered pretty much all of the more advanced bits.
Go
-
Use threads when they make code easier to reason about, not for performance
-
Closures don’t pass-by-value unless you pass a non-pointer argument explicitly
-
Cond implements a condition variable, a rendezvous point for goroutines waiting for or announcing the occurrence of an event.
Each Cond has an associated Locker L (often a *Mutex or *RWMutex), which must be held when changing the condition and when calling the Wait method.
A Cond must not be copied after first use.
- Calling
Broadcast
orWait
requires holding the lock to prevent the lost wakeup problem, whereBroadcast
may be called when the other thread is checking the condition and hasn’t calledWait
yet.
- Calling
-
Suggests that channels should be used sparingly in favor of locks, which seems antithetical to Go’s stated goals with channels.
Raft
- Deadlocks when peers are waiting on each other’s response