On Fri, Oct 08, 2004 at 10:03:50PM +0530, Vinu V wrote:
> 
> Thanks Jason for the reply.
> 
> But why is this considered not safe. Could this be a little more elaborated ?

Asynchronous signal handlers can be executed at any time.  This means that
you could be part way through locking a mutex in normal (non-signal
handler) code, then jump into the signal handler.  You might succeed in
locking the mutex in the signal handler, but the normal code assumed that
the mutex lock operation was atomic, and the signal handler has gone and
messed with the mutex behind the normal code's back.  Havoc ensues.

Pth does not protect against signal handlers in such critical sections of
code (mutex locking in this example), because the overhead would be
prohibitively expensive.  It is your responsibility not to do anything
dangerous in the signal handler.

In general, threads and signals do not mix well.  In practice, it s often
necessary to use both, but doing so is a delicate dance.  You would be well
advised to read a book that covers this issue in some detail.  My favorite
is "Programming with POSIX Threads", by David Butenhof.

Jason
______________________________________________________________________
GNU Portable Threads (Pth)            http://www.gnu.org/software/pth/
Development Site                      http://www.ossp.org/pkg/lib/pth/
Distribution Files                          ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots                 ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List                            [EMAIL PROTECTED]
Automated List Manager (Majordomo)           [EMAIL PROTECTED]

Reply via email to