基于 Futex 的锁定机制 [英] Futex based locking mechanism

查看:18
本文介绍了基于 Futex 的锁定机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我一个使用基于 futex 的锁定机制的例子吗?(适用于多核 x86 CPU、CentOS)

Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS)

推荐答案

Pthreads 的互斥锁是在最新版本的 Linux 上使用 futexes 实现的.Pthreads 是 Linux 上的标准 C 线程 API,并且是其中的一部分Posix 标准,因此您可以轻松地将程序移植到其他类 Unix 系统.除非您有非常特殊的需求,否则您应该避免直接使用 futex,因为它们很难正确使用 - 使用 pthread 或更高级别的特定于语言的 API(几乎肯定会使用 pthread 本身).

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 的锁定机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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