Summary:

I think I have an idea of what I want to do. Understand concurrency good enough, so I can build my own primitive and publish it on crates.io. It must reach a 1000 downloads by the end of 2026.

Mara Bos Book:

  • I wouldn't be able to write something like this on my own. But if now I am given a task to work with some data from different threads I would be able to do so without creating undefined behaviour.
  • Finished Reading Chapter 3.
    • Work
    • Stuff that happens in different threads can be matched in different ways. If we are interacting with the same variables from different threads, that may create errors. To prevent that we can create happens-before relationships between different threads using "release-stores" and "acquire-loads".
    • Practically this can help with Lazy Initialization.

Watching Stuff

  • The Cost of Concurrency Coordination with Jon Gjengset
    • If you have a lot of work use Mutexes, if you don't - don't. Cache miss would introduce a lot of overhead.
    • The left-right data structure is useful when we have a lot of short readers and not a lot of writers.
      • It is: Two copies of the data (l, r). Pointer points to the side all readers should read from. The other one is writer-owned.
      • When writer is done, the pointer switches to the other side.
      • Each reader has their own cache line. They just keep the counter of how many times they read the pointer. They do not need to talk to each other.
      • Reads are Wait and Lock free.
    • "Even the "lock-free" code can suffer from cache coherence".
    • Always remember CSE 142 and the Amdahl's law
    • Questions to ask yourself when you are choosing between Mutex, RwLock and left-right:
      • What is my read/write ratio?
      • How long is my critical section?
      • How many threads will content?
      • Do I need linearizability?