QWaitCondition

匿名 (未验证) 提交于 2019-12-03 00:22:01

bool
waitmutextime
bool
waitreadWriteLocktime
void
void

该类允许一个线程来告诉其他线程一些种情况已经被遇到。一个或者多个线程能阻塞等待为一个QWaitCondition来设置一个情况用wakeOne()或wakeAll()。使用wakeOne()来随机唤醒一个被选择的情况或者wakeAll()来唤醒所有的。


forever {      mutex.lock();      keyPressed.wait(&mutex);      do_something();      mutex.unlock();  }

forever {      getchar();      keyPressed.wakeAll();  }

forever {      mutex.lock();      keyPressed.wait(&mutex);      ++count;      mutex.unlock();        do_something();        mutex.lock();      --count;      mutex.unlock();  }

forever {      getchar();        mutex.lock();      // Sleep until there are no busy worker threads      while (count > 0) {          mutex.unlock();          sleep(1);          mutex.lock();      }      keyPressed.wakeAll();      mutex.unlock();  }


文章来源: QWaitCondition
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!