IntermediateTopic 62 of 104Software & Computing
Synchronisation primitives
Locks, semaphores and monitors coordinate concurrent code.
In depth
Synchronisation primitives coordinate concurrent execution: mutexes (mutual exclusion), semaphores, condition variables, monitors, read-write locks, barriers and atomics. Classic problems: producer-consumer, readers-writers, dining philosophers. Lock-free structures use compare-and-swap.
Key points
- Critical sections
- Memory ordering
- Spinlocks vs blocking
ExampleA mutex ensures one thread at a time updates a bank balance.
What is Synchronisation primitives?
Locks, semaphores and monitors coordinate concurrent code.
Why is it important to understand synchronisation primitives?
Synchronisation primitives coordinate concurrent code so that shared data stays correct, which is essential in any multithreaded program.
What is a monitor?
A construct that bundles shared data with the lock and condition variables that protect it, so access is controlled automatically.
What is the risk of using too many locks?
Contention slows the program, and incorrect locking can cause deadlock, so locks should be kept few and short.
How is Synchronisation primitives used in practice?
Typical applications include protecting a shared queue with a mutex, signalling a waiting thread when data is ready with a condition variable and limiting concurrent database connections with a counting semaphore.
What should I learn before Synchronisation primitives?
Study "File systems" first (topic 61 of 104 in Software & Computing). It covers the groundwork this topic builds on.
What are the key points of Synchronisation primitives?
Critical sections. Memory ordering. Spinlocks vs blocking.
Can you give an example of Synchronisation primitives?
A mutex ensures one thread at a time updates a bank balance.
What comes after Synchronisation primitives?
The next topic is "Virtualisation and containers", which builds directly on this one.
How difficult is Synchronisation primitives?
It is classed as Intermediate in Software & Computing (topic 62 of 104). It is an intermediate topic. Work through the beginner topics in Software & Computing first.