vendredi 21 avril 2017

Does tbb::parallel_for always utilize the calling thread

I have a piece of code where I am using tbb::parallel_for to multithread a loop, which is called by main thread. In that loop I need main thread to update the UI to reflect the progress. From what I have observed, tbb::parallel_for always uses the caller thread + N worker threads. However, I wonder, whether the usage of the calling threads is guaranteed or rather just happens to be the case?

Here is the sample code:

static thread_local bool _mainThread = false;  // false in all threads
_mainThread = true;                            // now true in main thread, but false in others
tbb::parallel_for(start, end, *this);

void Bender::processor::operator()(size_t i) const
{
...
            if(_mainThread)                     // only main thread will issue events
                ProgressUpdatedEvent(progress);
}

Thanks!

Aucun commentaire:

Enregistrer un commentaire