From owner-freebsd-threads@FreeBSD.ORG Thu Jan 3 22:31:20 2008 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29F5016A417; Thu, 3 Jan 2008 22:31:20 +0000 (UTC) (envelope-from jasone@freebsd.org) Received: from canonware.com (canonware.com [64.183.146.166]) by mx1.freebsd.org (Postfix) with ESMTP id 1177D13C457; Thu, 3 Jan 2008 22:31:20 +0000 (UTC) (envelope-from jasone@freebsd.org) Received: from [192.168.168.201] (unknown [192.168.168.201]) by canonware.com (Postfix) with ESMTP id 94B561298D3; Thu, 3 Jan 2008 14:02:50 -0800 (PST) Message-ID: <477D5B58.2040601@freebsd.org> Date: Thu, 03 Jan 2008 14:02:00 -0800 From: Jason Evans User-Agent: Thunderbird 1.5.0.12 (X11/20071018) MIME-Version: 1.0 To: Ivan Voras References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-threads@freebsd.org Subject: Re: Threads and signals X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jan 2008 22:31:20 -0000 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