问题描述
有人可以告诉我一个使用基于futex的锁定机制的例子? (对于muticore x86 CPU,CentOS)
Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS)
推荐答案
Pthreads的互斥是在最新版本的Linux上使用futexes实现的。 是Linux上的标准C线程API,是的Posix标准,因此您可以轻松地将程序移植到其他类Unix系统。你应该避免直接使用futexes,除非你有非常不寻常的需求,因为他们很难正确使用 - 使用pthreads或更高级别的语言特定的API(几乎肯定会使用pthreads本身)。
Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level, language-specific API (which will almost certainly use pthreads itself).
这篇关于基于Futex的锁定机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!