Windows Event equivalent in Qt
-
Windows has a synchronization primitive called Event. A thread can wait for an Event to be Signaled (similar to QWaitCondition), however, the difference is that QWaitCondition will only resume the threads that are waiting when wakeone/wakeall is called, But once Event is signaled it will simply allow a thread to continue once they come across Wait - they don't have to be already waiting.
Also, there are two kinds of Event - Manual Reset and Auto. Manual will need to be reset (after they are signaled) for the worker threads to stop again at the wait call. Auto will reset once a single worker has resumed from the wait call.
I need this functionality in my project. Does anyone know how to do this with Qt?
-
@Taytoo said in Windows Event equivalent in Qt:
Does anyone know how to do this with Qt?
With QWaitCondition and / or a QSemaphore.
-
@Christian-Ehrlicher said in Windows Event equivalent in Qt:
@Taytoo said in Windows Event equivalent in Qt:
Does anyone know how to do this with Qt?
With QWaitCondition and / or a QSemaphore.
From Qt Doc: https://doc.qt.io/archives/qt-4.8/qwaitcondition.html
Also, if some of the threads are still in do_something() when the key is pressed, they won't be woken up (since they're not waiting on the condition variable)
The documentation suggests a fix, however, it will causes the thread setting the event to Wait until the worker thread has started Wait - this is a really inefficient approach imo.
-
@Taytoo said in Windows Event equivalent in Qt:
this is a really inefficient approach imo.
Since QMutex, QSemaphore and QWaitCondition are basic building blocks and Windows does not provide anything other - what exactly are you trying to achieve?