Assume I have the following code
tbb::enumerable_thread_specific<std::set<int>> tls;
tbb::parallel_for(0, n, [&] (int i) {
auto &traversedVisited = tls.local();
// do a bfs using traversedVisited
});
Assume no other parallel_for are happening in the bfs parts (avoiding the problem mentioned in the task_isolation documentation). I know tls variable will provide thread-local storage, so there are no contentions between parallel_for tasks that are spawn on the same thread. However, if I understand correctly, those tasks (that are spawned on the same thread) share the same thread-local storage. Suppose tasks A and B are spawned on thread 1. Is it possible A is executed halfway and paused and B is turned in and starts to execute? If that is possible, then "traversedVisited" may not be valid for both A and B. Or are tbb tasks always atomic? If not, what's the solution for the situation mentioned at the beginning?