开发者

Reusing QMutex and QWaitCondition

开发者 https://www.devze.com 2023-02-15 18:36 出处:网络
Are QMutex+QWaitCondition objects reusable? I have a method to wait for some threads to complete. void FinishWait()

Are QMutex+QWaitCondition objects reusable? I have a method to wait for some threads to complete.

void FinishWait()
{
    mutex.lock();
    waitCondition(&qMutex, ULONG_MAX);
}

The waitCondi开发者_JAVA百科tion.wakeOne() is called on a different Thread.

The first call to FinishWait() works but the the second call doesn't return even if I specify timeout.


Assuming "mutex" and "qMutex" mean the same variable (it doesn't make much sense otherwise), you need to unlock the mutex after the wait() returns.

void FinishWait()
{
    mutex.lock();
    waitCondition.wait(&mutex);
    mutex.unlock();
}

0

精彩评论

暂无评论...
验证码 换一张
取 消