[Interest] Reset QThread requestedInterruption()
Alan Ezust
alan.ezust at gmail.com
Sun Jul 27 18:31:39 CEST 2014
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?
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.
On Sun, Jul 27, 2014 at 7:27 AM, Thiago Macieira <thiago.macieira at intel.com>
wrote:
> On Sunday 27 July 2014 13:22:03 Pérais Kévin wrote:
> > So I don't see why this functionality should be only used in order to
> > stop a thread running, and could be not be used to stop a JOB running in
> > the thread (but not the thread itself).
>
> The thing is that you can't reliably stop a job but not the thread by using
> this functionality. You'd introduce a race condition.
>
> Suppose you have two jobs queued for the same thread and you want to
> interrupt
> the first. So you do thread->requestInterrupt().
>
> However, say the job finished before the interruption came. In that case,
> it
> will not reset the flag or it will race the resetting of the flag. In
> either
> case, the flag remains set at the end of the first job.
>
> So the second job starts and realises the flag is set, so it interrupts
> itself,
> leading the third job to start.
>
> Anyway, the point is that this method is in QThread and thus is talking
> about
> interrupting the thread. If you want to interrupt jobs, add a flag to the
> job
> class.
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
> Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140727/818bf966/attachment.html>
More information about the Interest
mailing list