std::this_thread::yield() 用法?
有人可以提供 c++ 应用程序中 std::this_thread::yield() 用法的真实示例吗?
Can someone provide real-life example of std::this_thread::yield()
usage in c++ application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在std::lock的实现中使用了yield,在这里找到:
http://llvm.org /svn/llvm-project/libcxx/trunk/include/mutex
事实证明,当一次锁定多个锁/互斥锁时,当你无法获得一个锁/互斥锁时,你可以使应用程序更快 在以不同的顺序尝试锁定/互斥之前使用yield。
在此源代码中,我实际上调用了
sched_yield()
。但这只是为了按照我想要的方式获取标头依赖项。在此平台上,std::this_thread::yield()
只不过是对sched_yield()
的调用:http://llvm.org/svn/llvm-project/libcxx/trunk/include/thread
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.
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 platformstd::this_thread::yield()
is nothing more than a call tosched_yield()
:http://llvm.org/svn/llvm-project/libcxx/trunk/include/thread