Date: Thu, 03 Jan 2008 14:02:00 -0800 From: Jason Evans <jasone@freebsd.org> To: Ivan Voras <ivoras@freebsd.org> Cc: freebsd-threads@freebsd.org Subject: Re: Threads and signals Message-ID: <477D5B58.2040601@freebsd.org> In-Reply-To: <fljin9$crb$1@ger.gmane.org> References: <fljin9$crb$1@ger.gmane.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?477D5B58.2040601>