Hi all,

I wanted to discuss further about a suggestion a made in the bug tracker few days ago:
https://bugreports.qt-project.org/browse/QTBUG-40400

The topic is about the possibility to reset the interruption requested of a thread. Thiago Macieira told me that the functionality was implemented in order to stop the job. However, I disagree with that. Maybe the feature was thought only for that, but the Qt Documentation say about it:

http://qt-project.org/doc/qt-5/qthread.html#requestInterruption
" That request is advisory and it is up to code running on the thread to decide if and how it should act upon such request. This function does not stop any event loop running on the thread and does not terminate it in any way."

I first notice the "it is up to code running on the thread to decide IF and HOW it should act" I then "This function does not stop any event loop running on the thread and does not terminate it in any way."

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).

Let me explain a more concrete example of thread I am doing:

I have 3 worker objects that are meant to run in separate threads.

The first thread A have to read a file line by line and make few checks. It then pushes the QString to a queued shared buffer with thread B. Thread B take those results and parse the QString into a QStringList. It pushes the QStringList in a queued shared buffer with thread C. Thread C binds the QStringList parameters in a prepared SQL statement and execute it.

An object in my main thread manages the worker threads synchronisation. It setup the worker objects, create QThread instances, move the objects to the correct thread and launch those threads. When the user click on a button, It calls a method in the object Manager than manage to launch the differents methods in the worker threads using SIGNAL with parameters (since it is thread-safe).

If an error occurred in any of the worker threads, the concern thread send an error SIGNAL to the object Manager and stop his job (return in a method). Then the object Manager executes requestInterruption() to other worker thread so they stop their job too. At this stage, the user can correct the input data and launch again the whole work.

So he clicks again on the button. The object Manager send SIGNAL to all thread so they start working again with new data. The problem now is that 2 of the 3 threads will have the isInterruptionRequested() method returning TRUE, so they will stop has they believe an error occurred in an other thread. And then, I end up to a blocked situation where 2 threads ended their job, and the last one is waiting because the queued shared buffer are empty and it doesn't receive interruptionRequest() -- because no error SIGNAL have been sent to the object Manager since there was no errors.

So maybe my design is wrong. It's quite the first time I use threads. But having a method that can reset the requested interruption would have help me a lot!

I join you the forum discussion where I posted:
http://qt-project.org/forums/viewthread/44348/

Thank you for your participation.
Vinorcola.
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to