Multithreading 101: Concurrency Primitives From Scratch

Speaker: Arvid Gerstmann

Audience level: Beginner | Intermediate | Advanced

With Moore’s law declared dead, multi-threading is becoming even more important. To extract the last bit of performance out of recent CPUs, developers need full and thorough understanding of the used concurrency primitives. In this talk, I’ll explain and build the most used threading primitives from scratch. 

By implementing a simple Spinlock, I’ll demonstrate the very basics of a lock. This lock will be the first piece of the puzzle into building a Mutex. Next, you will learn how Linux Futexes work. The shown implementation in user space will make them not only available on Linux but also on other platforms. With all the pieces together, I’ll show you how to implement a modern Mutex using a Spinlock and Futex.

I’ll round up by giving you some guidance where and why to use which primitive. Explaining why certain primitives, for example, Spinlocks, are often not appropriate. In the end, you will not only have learned how a modern Mutex lock works and how it’s implemented but also how a Semaphore, Condition Variable, Latch, Shared Mutex, and several other concurrency primitives work.