0
我有一段代碼,我正在使用tbb::parallel_for
來多線程一個循環,該循環被主線程調用。在那個循環中,我需要主線程來更新UI以反映進度。從我觀察到的,tbb::parallel_for
總是使用調用者線程+ N工作線程。但是,我想知道,調用線程的使用是保證還是恰好是這種情況?tbb :: parallel_for是否總是使用調用線程
下面是示例代碼:
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);
}
謝謝!