Tong Zhou

@vesuppi

Joined on Aug 16, 2019

  • --- tags: lock, talk-notes --- # [Let's Talk Locks!] Table of contents This series is my notes for the talk https://www.infoq.com/presentations/go-locks/. ## Summary The talk talks about how locks are implemented in modern languages, taking Go as an example, since it has good concurrency design - its goroutines, which is user-space threads. ## Hardware lock primitives On Intel machines, `CMPXCHG` (compare-and-swap) used together with the `LOCK` prefix can be used to implement simple spin loc
     Like  Bookmark
  • --- tags: lock, talk-notes --- # [Let's Talk Locks!] #1: x86 LOCK prefix ## Cache coherence protocol and atomicity Cache coherence protocol can guarantee atomicity of a single cache line operation like `ADD`, imaging an implementation as follows: Before executing the `ADD`, the cache will broadcast INVALIDATE on the bus (supposed its state was `shared` before). On this bus, only one message can be broadcast each time. So other processors' copies will be Inv. If another process broadcast anot
     Like 1 Bookmark
  • # Two generals problem X and Y are two generals. They want to agree on a time to attack the enemy together. They will only attack if they know for sure the other knows they have reached an agreement. The channel is unreliable since their messenger can be captured and thus messaged undelivered. X → Y: attack at 10 pm. Y → X: ACK1. > Y doesn’t know if X has received ACK yet. So Y is pending. X → Y: ACK2. > X knows Y is pending, and is not sure if ACK2 has been received. > In real life, t
     Like  Bookmark