开发者

std::this_thread::yield() usage?

开发者 https://www.devze.com 2023-02-23 09:25 出处:网络
Can someone provide real-life example of std::this_thread::yield() usage in开发者_C百科 c++ application?I used yield in the implementation of std::lock, found here:

Can someone provide real-life example of std::this_thread::yield() usage in开发者_C百科 c++ application?


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 platform std::this_thread::yield() is nothing more than a call to sched_yield():

http://llvm.org/svn/llvm-project/libcxx/trunk/include/thread

0

精彩评论

暂无评论...
验证码 换一张
取 消