[英]What are the lowest locking primitives in Linux
What are the lowest locking primitives in linux. linux中最低的锁定原语是什么? I know about
futex_wait
and futex_wake
. 我知道
futex_wait
和futex_wake
。 But futexes can be used for signalling besides locking. 但是除了锁定之外,futex还可以用于信令。 What is the lowest locking primitive and where can I find it in the glibc library?
什么是最低的锁定原语,我在哪里可以在glibc库中找到它? Secondly, are the condition variables also based on futexes?
其次,条件变量是否也基于互斥量?
Read various documentations on futex -es, including futex(2) and futex(7) man pages. 阅读有关futex -es的各种文档,包括futex(2)和futex(7)手册页。 You'll learn that pthread locking primitives are implemented with a mixture of futexes and of assembly code (doing things non-expressible in portable C99)
您将了解到pthread锁定原语是通过futexes和汇编代码的混合实现的(在便携式C99中不可表达的事情)
(as I said in a comment) (正如我在评论中所说)
There is no such thing as "lowest", but locks for different scenarios and purposes and "signalling" is not the right criterion to distinguish different sorts of locks. 没有“最低”的东西,但是针对不同场景和目的的锁定以及“信令”不是区分不同种类的锁的正确标准。
atomic_flag
can be used for that. atomic_flag
可以用于此。 futex
as work horse underneath for the waiting part. futex
的组合实现的,作为等待部分的工作马。 Spinlocks are best used in contexts where you know that the critical phase only a handful of assembler instructions and where an interruption of the critical phase by the scheduler or signals is unlikely. 自旋锁最适用于您知道关键阶段只有少数汇编指令以及调度程序或信号不可能中断临界阶段的情况。 This is the case for much more contexts than many people tend to belief.
与许多人倾向于相信的情况相比,情况更多。 Therefore the
atomic_flag
is an important new feature in the C language. 因此,
atomic_flag
是C语言中一个重要的新功能。
The other locks are best used in context where active wait would eat up a substantial part of system resources. 其他锁最好用于主动等待占用大部分系统资源的环境中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.