- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suppose I have a tbb::parallel_pipeline consisting of 3 filters with mode serial_in_order, parallel and serial_in_order resp. In the first filter's operator(), for some reason, when dealing with some data (e.g., s struct A), the A.flag == true, means it is occupied by some other thread, and the function has to wait until A.flag == false.
My question is: what should be done? Just simply
while (A.flag) { }
to wait other thread make A.flag == false (Suppose A.flag can be made false later); or anything else?
Thanks a lot for any suggestion.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're waiting for a condition to be met and you don't want to busy-wait, we can try std::this_thread::yield as a hint to switch to executing another thread:
while (A->flag) {
std::this_thread::yield();
}
we also have tbb::task_arena::enqueue allowing to add a task to a TBB task arena in a more efficient way.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page