Multi-threading For Responsiveness
Posted: Thu Apr 03, 2014 7:27 pm
Hi all,
I love programming with threads: think for an hour, enter an & on the keyboard, watch it all crash and burn, think for hour, move the & somewhere, watch it all crash and burn, repeat....
I have a long running process (LRP), launched from a classic GUI, that I want to be able to kill by clicking a cancel button. However, the process should still be the only thing running.... in other words, the only thing the user can do in addition to letting the process continue is to kill it. He can take no other action.
Note that we don't (want to)know the internals of the LRP.... it may or may not loop, we cannot check from time to time if a variable has been updated.
At a minimum, we need one additional thread -- we need to thread the LRP so we have a thread id to kill.
One technique is to then go back to the main 0 thread and deactivate all (or most) of the other top level GUI objects leaving only access to the Cancel button that will kill the process.
Another option is use two additional threads, one for the LRP and another for a new form with a cancel button and a .Wait or ⎕DQ, and then do a ⎕TSYNC on the LRP thread, thus waiting on both the cancel form, and the process, before going back to the main thread.
The first technique has the advantage of being able to place a cancel button on an existing gui object, and the disadvantage of more housekeeping, tracking what the user may or may not do while the LRP is running. The opposite holds for the second technique.
Question: any obvious other solutions I am missing?
Also, if anyone has any easily shared multi-threading recipes or patterns for GUI responsiveness problems of any type, I would love to see them.
Thanks
I love programming with threads: think for an hour, enter an & on the keyboard, watch it all crash and burn, think for hour, move the & somewhere, watch it all crash and burn, repeat....
I have a long running process (LRP), launched from a classic GUI, that I want to be able to kill by clicking a cancel button. However, the process should still be the only thing running.... in other words, the only thing the user can do in addition to letting the process continue is to kill it. He can take no other action.
Note that we don't (want to)know the internals of the LRP.... it may or may not loop, we cannot check from time to time if a variable has been updated.
At a minimum, we need one additional thread -- we need to thread the LRP so we have a thread id to kill.
One technique is to then go back to the main 0 thread and deactivate all (or most) of the other top level GUI objects leaving only access to the Cancel button that will kill the process.
Another option is use two additional threads, one for the LRP and another for a new form with a cancel button and a .Wait or ⎕DQ, and then do a ⎕TSYNC on the LRP thread, thus waiting on both the cancel form, and the process, before going back to the main thread.
The first technique has the advantage of being able to place a cancel button on an existing gui object, and the disadvantage of more housekeeping, tracking what the user may or may not do while the LRP is running. The opposite holds for the second technique.
Question: any obvious other solutions I am missing?
Also, if anyone has any easily shared multi-threading recipes or patterns for GUI responsiveness problems of any type, I would love to see them.
Thanks