我使用 Qt 4.8.4 和 PyQt 4.10
这是我的测试代码:
#!/usr/bin/env python3
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Thread1(QThread):
def run(self):
print('thread1 %d' % QThread.currentThreadId())
mutex.lock()
QThread.sleep(5)
mutex.unlock()
class Thread2(QThread):
def run(self):
tid = QThread.currentThreadId()
print('%d tid enters' % tid)
mutex.lock()
print(tid)
app = QApplication(sys.argv)
print('main thread %d' % QThread.currentThreadId())
mutex = QMutex()
t = Thread1()
t.start()
QThread.sleep(1)
threads = [Thread2() for i in range(10)]
for thread in threads:
thread.start()
app.exec()
我的问题是:当 thread1 调用 mutex.unlock() 时,只有一个被阻塞的线程被唤醒。
这是输出:
main thread 140017224202048
thread1 140016996386560
140016987993856 tid enters
140016979601152 tid enters
140016962815744 tid enters
140016971208448 tid enters
140016672044800 tid enters
140016646866688 tid enters
140016638473984 tid enters
140016954423040 tid enters
140016663652096 tid enters
140016655259392 tid enters
140016987993856
该文件没有说明如何唤醒所有被阻止的内容。我怎样才能做到这一点?谢谢