G
Gabriele Bartolini
Hi,
I am writing an application in C++ on Linux, using threads (this is
my first experience with pthreads). The application itself is fine, it
is just that I wanted to handle asynchronous signals correctly, in
particular the SIGINT, preventing the application from stopping
ungracefully.
Indeed, I'd like to catch the signal, close everything in a
consistent way and stop the application.
I ended up structuring the application with a default behaviour of
ignoring any SIGINT, SIGHUP, SIGTERM and SIGUSR1 signals both for the
main process and the 'application threads'. Then I issued a dedicated
thread waiting for one of these signals whose task is to logically stop
the other threads and terminate.
When I press CTRL-C for instance, the thread catches the signal and
stops all the other threads. But, when no event is generated, the risk
is that the thread would be waiting for ever; that's why, when the
application normally finish without an asynchronous signal, I send a
'SIGUSR1' to the thread above and the application normally ends.
I want to know if I am improperly using the SIGUSR1 signal and if -
in this case - there are other ways of accomplishing this.
Thank you very much,
-Gabriele
I am writing an application in C++ on Linux, using threads (this is
my first experience with pthreads). The application itself is fine, it
is just that I wanted to handle asynchronous signals correctly, in
particular the SIGINT, preventing the application from stopping
ungracefully.
Indeed, I'd like to catch the signal, close everything in a
consistent way and stop the application.
I ended up structuring the application with a default behaviour of
ignoring any SIGINT, SIGHUP, SIGTERM and SIGUSR1 signals both for the
main process and the 'application threads'. Then I issued a dedicated
thread waiting for one of these signals whose task is to logically stop
the other threads and terminate.
When I press CTRL-C for instance, the thread catches the signal and
stops all the other threads. But, when no event is generated, the risk
is that the thread would be waiting for ever; that's why, when the
application normally finish without an asynchronous signal, I send a
'SIGUSR1' to the thread above and the application normally ends.
I want to know if I am improperly using the SIGUSR1 signal and if -
in this case - there are other ways of accomplishing this.
Thank you very much,
-Gabriele