我在C++中使用tbb編程。我不應該使用消息隊列,FIFO,PIPES等,因爲它是特定於平臺的。我應該使用tbb特定的API。使用tbb線程之間的同步
Thread1: // Pseuodo code exits as below
// I will take mutex
m_bIsNewSubsArrived = true;
StartSubscriptionTimer();
m_bIsFristSubsArrived = true;
// Spawn a thread here.
if(m_tbbTimerThread == NULL)
{
m_bIsTimerMutexTaken = true;
m_timerMutex.lock();
m_tbbTimerThread = new tbb::tbb_thread(&WaitForTimerMutex, this);
if (m_tbbTimerThread->native_handle() == 0)
{
// report error and return.
return;
}
}
// Thread 1 exited.
In another thead I am releasing mutex which is taken above.
Thread 2.
m_timerMutex.unlock();
m_bIsTimerMutexTaken = false;
Thread 3:
// I am waiting for mutex
m_timerMutex.lock();
在上面的代碼中的問題,我覺得是線程1,其中被鎖定m_timerMutex不relased所以我覺得線程2都不能夠開鎖。線程3永遠被阻止。
我想我可以使用sempahore,但是在TBB中sempahore的API是什麼。
什麼是最好的技術,我可以做到這一點與睡覺和使用tbb特定的API。
感謝您的時間和幫助。
你不能使用[concurrent_queue_cls](http://software.intel.com/sites/products/documentation/doclib/tbb_sa/help/reference/containers_overview/concurrent_queue_cls.htm) - 它基本上是一個消息隊列。 –