Din*_*ray 0 c++ multithreading c++11
Program language: C++ 11
I use pipeline threads mode to deal data.
One thread generate data.
One thread process data.
While no data to deal, which is the best way to yield thread?
Now I use
std::this_thread::sleep_for(100ms);
Run Code Online (Sandbox Code Playgroud)
Which is the best way to yield thread?
It is std::this_thread::yield.
Now I use
Run Code Online (Sandbox Code Playgroud)std::this_thread::sleep_for(100ms);
While sleeping does yield the thread as a side-effect, that's not all that it does. As the name implies, it blocks the thread for a given time.
However, it is unclear how yielding or sleeping would be useful in a producer / consumer case such as what you describe. What you probably should do is wait on a condition variable instead.
| 归档时间: |
|
| 查看次数: |
99 次 |
| 最近记录: |