Threads and signals
    Jason Evans 
    jasone at freebsd.org
       
    Thu Jan  3 14:31:20 PST 2008
    
    
  
Ivan Voras wrote:
> How do threads interact with signals? In particular, if I have a "main"
> process thread (the one started by main()) which generates items for a
> mutex-protected queue which are consumed by a worker thread, and I need
> to insert an item in the queue from the signal handler, am I correct
> that doing pthread_mutex_lock() from the signal handler could deadlock
> if the signal handler is executed by any of the threads (and the mutex
> is non-recursive)?
> 
> How is this solved in general? By recursive mutexes?
This is solved in general by not doing dangerous things in signal 
handlers.  Signal handler functions are very restricted in what they can 
safely do.  You really need to read Butenhof's book, _Programming with 
POSIX Threads_; it has excellent coverage on this topic.
Jason
    
    
More information about the freebsd-threads
mailing list