QMutex.unlock doesn't wake all blocked threads
Question: I use Qt 4.8.4 and PyQt 4.10

Here is my test code:

    
    
    #!/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()
    

My problem is: when thread1 calls mutex.unlock(), only one blocked thread is
waken.

Here is the output:

    
    
    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
    

The document doesn't say anything about how to wake all blocked. How can I do
that? THX


Answer: A [mutex](http://qt-project.org/doc/qt-4.8/qmutex.html#details) by definition
limits (or protects) one piece of code so that only _one_ thread can access it
at a time. So you can't "wake" all threads if they all wait for one mutex,
maybe you need many mutexes (one for each "resource") or depending or the
design and constrains or your real project (since you posted the code from a
"test application") maybe a [semaphore](http://qt-
project.org/doc/qt-4.8/qsemaphore.html#details) will be better suited.

