定义“同步原语". [英] Definition of "synchronization primitive"

查看:139
本文介绍了定义“同步原语".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同步原语到底是什么意思?例如:互斥锁,关键部分,等待计时器,事件,监视器,条件变量,信号量.它们都是同步原语吗?我还没有列出其他同步原语吗?这些是有效的问题吗?

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?

推荐答案

同步原语是平台(例如操作系统)为其用户提供的简单软件机制,目的是支持线程或进程同步.它们通常是使用较低级的机制(例如原子操作,内存屏障,自旋锁,上下文切换等)构建的.

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).

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

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.

这篇关于定义“同步原语".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆