bool | |
bool | |
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