Re: Signals, threads and the use of SIGUSR1
From: Loic Domaigne (loic-dev_at_gmx.net)
Date: 10/03/03
- Next message: Fabio: "Re: Directory-change notification on Solaris"
- Previous message: Maurizio Loreti: "Re: Directory-change notification on Solaris"
- In reply to: Gabriele Bartolini: "Signals, threads and the use of SIGUSR1"
- Next in thread: Gabriele Bartolini: "Re: Signals, threads and the use of SIGUSR1"
- Reply: Gabriele Bartolini: "Re: Signals, threads and the use of SIGUSR1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 03 Oct 2003 11:51:59 +0000
Hello Gabriele,
> I am writing an application in C++ on Linux, using threads (this is
> my first experience with pthreads).
<snip>
> 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.
Looks good.
> 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.
Well, I don't know what kind of actions your "signal handler" thread
- the one that is waiting in sigwait() - does exactly, but I guess,
that's OK to just terminate your process as usual, without explicitely
terminate that thread. When the main thread returns, or one of your threads
terminate the process, then your signal handler thread shall be
automatically terminated.
Only when you need some "clean-up" actions (e.g. be sure that the
destructor of some objects is called etc.) in the signal handler thread
upon the normal process ending, then yes, you need to gracefully terminate
that thread.
Using SIGUSR1 is OK with the 'recent' Pthreads lib (I meant younger
than 2 years old). Indeed, older LinuxThreads library used SIGUSR1 and
SIGUSR2 for internal communications, so you weren't able to use that
signal in your application.
As noted by another poster, if you need to do some clean-up in the
signal thread, you could alternatively used pthread_cancel(). Uses
a deferred cancelation only at sigwait() since that function is a
cancellation point. But using SIGUSR1 is also fine.
Regards,
Loic.
-- Article posté via l'accès Usenet http://www.mes-news.com Accès par Nnrp ou Web
- Next message: Fabio: "Re: Directory-change notification on Solaris"
- Previous message: Maurizio Loreti: "Re: Directory-change notification on Solaris"
- In reply to: Gabriele Bartolini: "Signals, threads and the use of SIGUSR1"
- Next in thread: Gabriele Bartolini: "Re: Signals, threads and the use of SIGUSR1"
- Reply: Gabriele Bartolini: "Re: Signals, threads and the use of SIGUSR1"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|