I have the following situation:
Two C ++ 11 threads are working on computation, and they are synchronized via std :: mutex.
Thread A locks the mutex until the data is ready to execute Thread B. When the mutex is unlocked, B. starts to work.
Thread B attempts to lock the mutex and locks until it is unlocked by thread A.
void ThreadA (std::mutex* mtx, char* data)
{
mtx->lock();
mtx->unlock();
}
void ThreadB (std::mutex* mtx, char* data)
{
mtx->lock();
}
It is argued that Thread A may first lock the mutex.
Now I wonder if mtx->lock()
Thread B will be active or passive. Thus, Thread B checks the status of the mutex and spends processor time or is allocated passively using the scheduler when the mutex is unlocked.
++ , , .
, , std::mutex
plattform ?