[H-GEN] pthreads

Andrae Muys a.muys at mailbox.uq.edu.au
Wed Aug 25 23:53:21 EDT 1999


[ Humbug *General* list - semi-serious discussions about Humbug and
Unix-related topics. ]

On Thu, 26 Aug 1999, Raymond Smith wrote:

> On Thu, 26 Aug 1999, Allen Grace wrote:
> > ...reading the manpage for pthread_mutex functions in Linux, one is
> > explicitly warned not to call pthread_mutex_lock and
> > pthread_mutex_unlock from a signal handler (risk of deadlock). 
> > 
> > 1. Is this only a problem for Linux, or is this a bad idea for all
> > Unices?
> 
> It is a Bad Thing to do complicated stuff inside a signal handler.

Signal handlers are really really bad news when using threads.  Instead
try spawning a "signal handler thread" and turn off signals for your
other threads..

> > 2. What if I really want to do this? because (just for instance :) ) I
> > might have a thread which modifies a structure, and then signals the
> > parent process that the structure has been modified, so that it in turn
> > can do things with it (including modify it).
> > What else could one do?
> 
> You do not really want to do this. If you are using threads I would
> suggest have a global variable you set in the signal handler and another
> thread which periodically polls this variable and performs appropriate
> actions.

In fact the real problem is that mutex's aren't suitable for
syncronisation purposes.  Instead you should be using condition variables.
If you haven't yet, get your hands on "Programming With Threads, Kleiman
et al, Sunsoft Press", and also have a look at my pthreads tutorial
http://www.uq.edu.au/~cmamuys/humbug/talks/pthread (iirc).

Andrae

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Andrae Muys              "Never ascribe to malice that which is adequately
andrae at humbug.org.au      explained by incompetence." - Napoleon Bonaparte


--
This is list (humbug) general handled by majordomo at lists.humbug.org.au .
Postings only from subscribed addresses of lists general or general-post.



More information about the General mailing list