Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Definition of "synchronization primitive"

What exactly does the term synchronization primitive mean? For example: mutex, critical section, waitable timer, event, monitor, conditional variable, semaphore. Are all of them synchronization primitives? Are there any other synchronization primitives I have not listed? And are these a valid questions?

like image 422
Loom Avatar asked Nov 05 '11 01:11

Loom


People also ask

What is a Synchronisation primitive?

Synchronization primitives are simple software mechanisms provided by a platform (e.g. operating system) to its users for the purposes of supporting thread or process synchronization. They're usually built using lower level mechanisms (e.g. atomic operations, memory barriers, spinlocks, context switches etc).

Why do we need synchronization primitives?

Several synchronization primitives have been introduced to aid in multithreading the kernel. These primitives are implemented by atomic operations and use appropriate memory barriers so that users of these primitives do not have to worry about doing it themselves.

What is semaphore primitive?

A semaphore is a very general synchronization primitive, and most other synchronization operations can be reduced to semaphore operations (this is how Nachos implements locks and condition variables). Semaphores are in most cases too basic an abstraction to be used effectively.


2 Answers

Synchronization primitives are simple software mechanisms provided by a platform (e.g. operating system) to its users for the purposes of supporting thread or process synchronization. They're usually built using lower level mechanisms (e.g. atomic operations, memory barriers, spinlocks, context switches etc).

Mutex, event, conditional variables and semaphores are all synchronization primitives. So are shared and exclusive locks. Monitor is generally considered a high-level synchronization tool. It's an object which guarantees mutual exclusion for its methods using other synchronization primitives (usually exclusive locks with condition variables to support waiting and signaling). In some contexts when monitor is used as a building block it is also considered a synchronization primitive.

Critical section is not a synchronization primitive. It's a part of an execution path that must be protected from concurrent execution in order to maintain some invariants. You need to use some synchronization primitives to protect critical section.

like image 158
Adam Zalcman Avatar answered Nov 10 '22 06:11

Adam Zalcman


As suggested by @Loom, I'm adding this list, offered by the Colombia University, as an answer to your question.

Also check out this article from Microsoft, dated to 03/2017 (I have a feeling it is older, but so is the article from Colombia University).

From what I gathered, synchronization primitives are not well defined, in the sense that there isn't an official list of them.

like image 29
zook2005 Avatar answered Nov 10 '22 07:11

zook2005