multithreading “同步原语”的定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8017507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:17:16  来源:igfitidea点击:

Definition of "synchronization primitive"

multithreadinglanguage-agnosticsynchronizationterminology

提问by Loom

What exactly does the term synchronization primitivemean? 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?

术语同步原语究竟是什么意思?例如:互斥锁、临界区、可等待定时器、事件、监视器、条件变量、信号量。它们都是同步原语吗?有没有我没有列出的其他同步原语?这些是有效的问题吗?

回答by Adam Zalcman

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.

互斥、事件、条件变量和信号量都是同步原语。共享锁和排他锁也是如此。Monitor 通常被认为是一种高级同步工具。它是一个对象,它使用其他同步原语(通常是带有条件变量的排他锁以支持等待和信令)保证其方法的互斥。在某些情况下,当监视器用作构建块时,它也被视为同步原语。

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.

临界区不是同步原语。它是执行路径的一部分,必须防止并发执行以维护一些不变量。您需要使用一些同步原语来保护临界区。

回答by zook2005

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

正如@Loom 所建议的,我正在添加这个由哥伦比亚大学提供的列表,作为对您问题的回答。

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

另请查看Microsoft 的这篇文章,日期为 03/2017(我感觉它更旧,但哥伦比亚大学的文章也是如此)。

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

从我收集到的信息来看,同步原语并没有很好地定义,因为它们没有官方列表。