I am using tbb programming in C++. I am not supposed to use message queue, FIFO, PIPES etc as it is platform specific. I am supposed to use tbb specific API's.
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();
In above code problem I think is thread 1 which locked m_timerMutex is not relased so I think thread2 not able to unlock. And thread 3 is blocked for ever.
I think I can use sempahore, but what are API's for sempahore in TBB.
What is the best technique I can do this with out sleeping and using tbb specific API's.
Thanks for your time and help.