[Interest] Reset QThread requestedInterruption()
Thiago Macieira
thiago.macieira at intel.com
Thu Jul 31 03:01:13 CEST 2014
On Sunday 27 July 2014 09:31:39 Alan Ezust wrote:
> If your thread is running an event loop, it sounds like what you really
> want is a way to tell the event loop to start/stop processing events from
> another thread, am I right?
I'm assuming you meant "events posted from another thread". Each thread has an
event dispatcher and its own event queue. One thread will never process events
from another thread.
Events can be moved across threads though: they are moved when their target
object moves threads.
> You can use a QWaitCondition and a QMutex when isInterruptionRequested, and
> put that thread into a non-busy waiting state. Then you call the
> waitCondition's wakeOne() from another thread when you want to wake it up
> again.
If you have a QWaitCondition and a QMutex, you don't need
isInterruptionRequested. You can just use a regular boolean somewhere.
You could try to use the two together, but I don't see the point.
if the current thread is sleeping, the other thread can do requestInterrupt()
and then waitcond.wakeOne() or wakeAll(). When this thread gets woken up, it
verifies that the interruption was requested and exits.
However, this does NOT work for checking before sleeping, as that introduces a
race condition between checking the isInterruptionRequested flag and the
sleeping in waitcond.wait(). To remove this race condition, the calling thread
must lock the mutex before doing requestInterrupt(). At this point, since the
mutex was locked anyway, you we go back to "you can just use regular boolean
somewhere".
Conclusion: I still don't see the need to change QThread.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list