Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
707 views
in Technique[技术] by (71.8m points)

multithreading - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...