I
Ioannis Gyftos
I am developing a little utility for my desktop, and at some point I
have a 'worker' thread and a (main) GUI thread. Depending on
circumstances, on some rare cases I wanted to display a window, but
since i use the QT library, the window must be created from the main
thread. So I need the 'worker' thread to interrupt its work, notify
the main thread, the main thread to display it, and then restart the
whole process after user interaction.
The way I implemented this, is that I throw an exception which is
caught at the run() function of the worker thread, and then it
notifies the GUI thread (through the signal/slot mechanism which is
offtopic). So far this has worked nicely on my machine.
(Though I am not sure if this the best approach since it's for
personal use, but for academic reasons, if you have a better idea I am
more than happy to hear it ).
My question is, supposing I have multiple 'worker' threads and an
exception occurs, is this thread safe? I googled a bit, and found that
some compilers have thread-safety on exceptions, but some don't. What
does the standard say? I would like to maintain a little portability
on the major desktop OS, so even if only the major desktop compilers
support this it is acceptable.
have a 'worker' thread and a (main) GUI thread. Depending on
circumstances, on some rare cases I wanted to display a window, but
since i use the QT library, the window must be created from the main
thread. So I need the 'worker' thread to interrupt its work, notify
the main thread, the main thread to display it, and then restart the
whole process after user interaction.
The way I implemented this, is that I throw an exception which is
caught at the run() function of the worker thread, and then it
notifies the GUI thread (through the signal/slot mechanism which is
offtopic). So far this has worked nicely on my machine.
(Though I am not sure if this the best approach since it's for
personal use, but for academic reasons, if you have a better idea I am
more than happy to hear it ).
My question is, supposing I have multiple 'worker' threads and an
exception occurs, is this thread safe? I googled a bit, and found that
some compilers have thread-safety on exceptions, but some don't. What
does the standard say? I would like to maintain a little portability
on the major desktop OS, so even if only the major desktop compilers
support this it is acceptable.