Linux FUTEX_WAIT 和 FUTEX_WAIT_PRIVATE 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9983765/
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-08-06 05:33:45  来源:igfitidea点击:

What is the difference between FUTEX_WAIT and FUTEX_WAIT_PRIVATE?

linuxstracefutex

提问by Gabriel Southern

I have been tracing a process with strace and have seen entries such as:

我一直在用 strace 跟踪一个进程,并看到了如下条目:

futex(0x7ffff79b3e00, FUTEX_WAKE_PRIVATE, 1) = 1                                                                
futex(0x7ffff79b3e00, FUTEX_WAIT_PRIVATE, 2, NULL) = 0 

However, when I looked at the man page for futexI have only seen entries such as FUTEX_WAITand FUTEX_WAKE. So my question is what does _PRIVATEthat is appended to the end of these names in my strace output mean? For instance is there any difference between something like FUTEX_WAKEthat is documented in the futex man page and FUTEX_WAKE_PRIVATEthat I see in the strace output or can I assume that they are the same when I am trying to understand what is happening with the program I am debugging.

但是,当我查看futex手册页时,我只看到了诸如FUTEX_WAITand 之类的条目FUTEX_WAKE。所以我的问题是_PRIVATE在我的 strace 输出中附加到这些名称的末尾是什么意思?例如FUTEX_WAKE,futex 手册页中记录的内容与FUTEX_WAKE_PRIVATE我在 strace 输出中看到的内容之间是否有任何区别,或者当我试图了解我正在调试的程序发生的情况时,我是否可以假设它们是相同的。

采纳答案by je4d

This is an optimization done by linux/glibc to make futexes faster when they're not shared between processes. Glibc will use the _PRIVATEversions of each of the futex calls unless the PTHREAD_PROCESS_SHAREDattribute is set on your mutex

这是由 linux/glibc 完成的优化,当 futex 不在进程之间共享时使它们更快。Glibc 将使用_PRIVATE每个 futex 调用的版本,除非PTHREAD_PROCESS_SHARED在您的互斥锁上设置了该属性

It's explained in more detail here: http://lwn.net/Articles/229668/

这里有更详细的解释:http: //lwn.net/Articles/229668/

For the purposes of your debugging, you can just ignore the _PRIVATEsuffixes

出于调试目的,您可以忽略_PRIVATE后缀