In Qt, I have a method which contains a mutex lock and unlock. The problem is when the mutex is unlock it sometimes take long before the other thread gets the lock back. In other words it seems the same thread can get the lock back(method called in a loop) even though another thread is waiting for it. What can I do about this? One thread is a qthread and the other thread is the main thread.
Share
You can have your thread that just unlocked the mutex relinquish the processor. On Posix, you do that by calling
pthread_yield()and on Windows by callingSleep(0).That said, there is no guarantee that the thread waiting on the lock will be scheduled before your thread wakes up again.