Threads and signals

Kip Macy kip.macy at gmail.com
Thu Jan 3 15:02:53 PST 2008


On Jan 3, 2008 1:05 PM, Ivan Voras <ivoras at freebsd.org> wrote:
> Hi,
>
> 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?
>

Very few functions are async signal safe. As a general rule you should
avoid doing things from the signal handler itself. On some operating
systems such as Solaris, most things will "just work". However, that
can't be relied upon across platforms.

 -Kip


More information about the freebsd-threads mailing list