std :: this_thread :: yield()用法? [英] std::this_thread::yield() usage?
问题描述
有人可以在c ++应用程序中提供 std :: this_thread :: yield()
的现实例子吗?
Can someone provide real-life example of std::this_thread::yield()
usage in c++ application?
推荐答案
我在执行std :: lock时使用了yield,在这里:
I used yield in the implementation of std::lock, found here:
http://llvm.org/svn/llvm-project/libcxx/trunk/include/mutex
事实证明,当一次锁定多个锁/互斥锁时,如果你没有得到一个,你可以使应用程序更快
It turns out that when locking multiple locks/mutexes at a time, when you fail to get one, you can make the application faster by using yield prior to trying the locks/mutexes in a different order.
在这个源代码中,我实际上调用 sched_yield()
。但这只是为了获得头依赖的方式,我想要的方式。在这个平台上 std :: this_thread :: yield()
只不过是调用 sched_yield()
:
In this source code I'm actually calling sched_yield()
. But that is only for the purpose of getting the header dependency the way I wanted it. On this platform std::this_thread::yield()
is nothing more than a call to sched_yield()
:
http://llvm.org/ svn / llvm-project / libcxx / trunk / include / thread
这篇关于std :: this_thread :: yield()用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!