From owner-freebsd-threads@FreeBSD.ORG Thu Jan 3 23:02:53 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 7064116A419 for ; Thu, 3 Jan 2008 23:02:53 +0000 (UTC) (envelope-from kip.macy@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.178]) by mx1.freebsd.org (Postfix) with ESMTP id 319E613C47E for ; Thu, 3 Jan 2008 23:02:53 +0000 (UTC) (envelope-from kip.macy@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so10486349waf.3 for ; Thu, 03 Jan 2008 15:02:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=Dui7ZMXaonpyYohcss8Vf4kgmD2kR2cgK+8eQqX9Yfk=; b=mranUvQfyoWlrRk4a/DyBU3Zn7XVaWErvcEd3vrijhjUfv2CZrO4/+1jmhzNy8QKJj01tE3PTBR+Dcr5BME7C259gXMYToua8Dk2yTe4+WmwZAGOyZDLfdB3OjKxM1iIScZK8Lu8rb9x4XqITx8qzOQ7/mcTjzi/8QGKuCU1BVo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=aPJC8xa8vcvtENzjbgLGyGE/OYxsgsMIlolCkLbO6A/IafBKW6nQ370AFtIqIC7BTesO5mlZJLQZlf+cPTXw+rOKnYHKgpkv7IOwVbKemf0rCIX85RBfDxo+U2hj9swDzD+FopP1d8IrgdkpV3Xc6DRDMNecEMWDXD6eNqw+lkA= Received: by 10.114.159.1 with SMTP id h1mr4309841wae.122.1199399932683; Thu, 03 Jan 2008 14:38:52 -0800 (PST) Received: by 10.114.255.11 with HTTP; Thu, 3 Jan 2008 14:38:52 -0800 (PST) Message-ID: Date: Thu, 3 Jan 2008 14:38:52 -0800 From: "Kip Macy" To: "Ivan Voras" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: 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 23:02:53 -0000 On Jan 3, 2008 1:05 PM, Ivan Voras 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