From owner-freebsd-threads@FreeBSD.ORG Tue Jan 1 06:00:07 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5CBFB16A4CE for ; Tue, 1 Jan 2008 06:00:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 338DD13C4F2 for ; Tue, 1 Jan 2008 06:00:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m01607Cs030967 for ; Tue, 1 Jan 2008 06:00:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m01607e2030966; Tue, 1 Jan 2008 06:00:07 GMT (envelope-from gnats) Resent-Date: Tue, 1 Jan 2008 06:00:07 GMT Resent-Message-Id: <200801010600.m01607e2030966@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, qogsyutz Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49A1B16A418 for ; Tue, 1 Jan 2008 05:59:29 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 21EF213C461 for ; Tue, 1 Jan 2008 05:59:29 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m015wgBD087582 for ; Tue, 1 Jan 2008 05:58:42 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m015wgD7087581; Tue, 1 Jan 2008 05:58:42 GMT (envelope-from nobody) Message-Id: <200801010558.m015wgD7087581@www.freebsd.org> Date: Tue, 1 Jan 2008 05:58:42 GMT From: qogsyutz To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: threads/119220: qogsyutz 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: Tue, 01 Jan 2008 06:00:07 -0000 >Number: 119220 >Category: threads >Synopsis: qogsyutz >Confidential: no >Severity: critical >Priority: medium >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Tue Jan 01 06:00:06 UTC 2008 >Closed-Date: >Last-Modified: >Originator: qogsyutz >Release: qogsyutz >Organization: qogsyutz >Environment: qogsyutz >Description: hjfbcnqy http://ulcwedte.com kjbfflfa xbvcqudr >How-To-Repeat: qogsyutz >Fix: qogsyutz >Release-Note: >Audit-Trail: >Unformatted: From owner-freebsd-threads@FreeBSD.ORG Wed Jan 2 18:47:58 2008 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4DC9C16A419; Wed, 2 Jan 2008 18:47:58 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 267A813C46E; Wed, 2 Jan 2008 18:47:58 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from freefall.freebsd.org (jhb@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m02IlwKT014862; Wed, 2 Jan 2008 18:47:58 GMT (envelope-from jhb@freefall.freebsd.org) Received: (from jhb@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m02Ilvm5014858; Wed, 2 Jan 2008 18:47:57 GMT (envelope-from jhb) Date: Wed, 2 Jan 2008 18:47:57 GMT Message-Id: <200801021847.m02Ilvm5014858@freefall.freebsd.org> To: ueyciqnp@fkifvxmv.com, jhb@FreeBSD.org, freebsd-threads@FreeBSD.org From: jhb@FreeBSD.org Cc: Subject: Re: threads/119220: qogsyutz 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: Wed, 02 Jan 2008 18:47:58 -0000 Synopsis: qogsyutz State-Changed-From-To: open->closed State-Changed-By: jhb State-Changed-When: Wed Jan 2 18:47:46 UTC 2008 State-Changed-Why: Spam. http://www.freebsd.org/cgi/query-pr.cgi?pr=119220 From owner-freebsd-threads@FreeBSD.ORG Thu Jan 3 21:05:57 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 BACD716A54C for ; Thu, 3 Jan 2008 21:05:57 +0000 (UTC) (envelope-from gofdt-freebsd-threads@m.gmane.org) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mx1.freebsd.org (Postfix) with ESMTP id 7346B13C46E for ; Thu, 3 Jan 2008 21:05:57 +0000 (UTC) (envelope-from gofdt-freebsd-threads@m.gmane.org) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JAXGE-0003wi-9P for freebsd-threads@freebsd.org; Thu, 03 Jan 2008 21:05:54 +0000 Received: from 78-0-90-175.adsl.net.t-com.hr ([78.0.90.175]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Jan 2008 21:05:54 +0000 Received: from ivoras by 78-0-90-175.adsl.net.t-com.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 03 Jan 2008 21:05:54 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-threads@freebsd.org From: Ivan Voras Date: Thu, 03 Jan 2008 22:05:43 +0100 Lines: 33 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig4E7D4E2C509ACF61C53D1B22" X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 78-0-90-175.adsl.net.t-com.hr User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) X-Enigmail-Version: 0.95.5 Sender: news Subject: 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 21:05:57 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4E7D4E2C509ACF61C53D1B22 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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? --------------enig4E7D4E2C509ACF61C53D1B22 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHfU4nldnAQVacBcgRAmYaAJ9otYyttlpdgswiBBpjPaLCgxJgEQCdFUpF tDXHVbYxeYKDtFMn5YZ8kNA= =ttN4 -----END PGP SIGNATURE----- --------------enig4E7D4E2C509ACF61C53D1B22-- 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 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 From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 00:03:30 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 1841116A41A; Fri, 4 Jan 2008 00:03:30 +0000 (UTC) (envelope-from jp@devnull.cz) Received: from smtp1.vol.cz (smtp1.vol.cz [195.250.128.78]) by mx1.freebsd.org (Postfix) with ESMTP id CB7C113C469; Fri, 4 Jan 2008 00:03:29 +0000 (UTC) (envelope-from jp@devnull.cz) Received: from shark.devnull.cz (shark.devnull.cz [195.250.130.194]) by smtp1.vol.cz (Postfix) with ESMTP id 411B985E30; Fri, 4 Jan 2008 00:42:15 +0100 (CET) Date: Fri, 4 Jan 2008 00:42:15 +0100 (CET) From: Jan Pechanec To: Kip Macy In-Reply-To: Message-ID: <20080104003530.F93027@shark.devnull.cz> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: Ivan Voras , 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: Fri, 04 Jan 2008 00:03:30 -0000 On Thu, 3 Jan 2008, Kip Macy wrote: >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. hi Kip, just to add, you can use pthread_mutex_lock() there from signal handlers since they are MT-safe but if you use it on the same mutex then you are still screwed. Well, it will probably work since be default mutexes on Solaris are of type PTHREAD_MUTEX_NORMAL but as you say - it depends on the platform. Locking the same mutex twice is plain wrong. By the way, the default type on FreeBSD is PTHREAD_MUTEX_ERRORCHECK. very probably the only reasonable way how to work with signals with threads is to mask all threads but one and to use sigwait(2) there. Butenhof has it all, as already said. J. -- Jan Pechanec http://www.devnull.cz From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 01:20:47 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 8FCE516A41A for ; Fri, 4 Jan 2008 01:20:47 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 7B92D13C45A for ; Fri, 4 Jan 2008 01:20:47 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 8982F1A4D82; Thu, 3 Jan 2008 17:18:21 -0800 (PST) Date: Thu, 3 Jan 2008 17:18:21 -0800 From: Alfred Perlstein To: Ivan Voras Message-ID: <20080104011821.GD76698@elvis.mu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i 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: Fri, 04 Jan 2008 01:20:47 -0000 * Ivan Voras [080103 13:03] 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? You need to block/unblock signals or use sigwait. So basically your code will look something like: main() { defer_signals(); signal(SIGWHATEVER, &handler); make_threads(); for ( ;; ) { do_stuff(); undefer_signals(); /* right here "handler" may be called */ defer_signals(); } } Another option is to have one of your threads use sigwait() and do the operation synchronously. Another is to write(2) to a pipe(2) from within your signal handler that one of your threads is select(2)/poll(2)/kevent(2) against, then the selecting thread can read the byte, thereby clearing the event and then queue the workitem synchronously. -- - Alfred Perlstein From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 11:50:50 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 6B13916A419 for ; Fri, 4 Jan 2008 11:50:50 +0000 (UTC) (envelope-from ivoras@gmail.com) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.186]) by mx1.freebsd.org (Postfix) with ESMTP id B0E0A13C45D for ; Fri, 4 Jan 2008 11:50:49 +0000 (UTC) (envelope-from ivoras@gmail.com) Received: by rv-out-0910.google.com with SMTP id l15so6541461rvb.43 for ; Fri, 04 Jan 2008 03:50:49 -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:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=6vjBoIfgMVRUz4TfDD0Tk6M5Dcr+WBo9RPv4pkDneZ0=; b=iTEYtp3yvUhUvDRnubalUJjnGBTEvsmXdFh0aZc72t71c8Fy1TGn2iAC5jINiqTh8RQGegRnCw+r8J9sX3gWPyY/nSmWSWwHr+oBJvfJC8WQU8QFzTJHEBG+cggwK+MH9eqaIBbDoj6J5atOnLTgztMty7xDr8CuxU0LUHvJ/ko= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=Nm6PjfKVLBqTc8UBHGSslNw5Toki9ndCtIU5YEOb53hw05MnfBPkYga95ShlsyNC7zNexcYl0pznLcvxNOgAsieZdB2AgQolL3zzM+SaRd+2En3yEKeEOj9j9E46Ljpjw/gEZ/fMyaviYnmfLjmYfBtiqEoSbtHQMCBBwR9PxKI= Received: by 10.140.171.4 with SMTP id t4mr1729415rve.187.1199445937368; Fri, 04 Jan 2008 03:25:37 -0800 (PST) Received: by 10.141.212.1 with HTTP; Fri, 4 Jan 2008 03:25:37 -0800 (PST) Message-ID: <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> Date: Fri, 4 Jan 2008 12:25:37 +0100 From: "Ivan Voras" Sender: ivoras@gmail.com To: "Alfred Perlstein" In-Reply-To: <20080104011821.GD76698@elvis.mu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080104011821.GD76698@elvis.mu.org> X-Google-Sender-Auth: f9eb673a94ec6bce 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: Fri, 04 Jan 2008 11:50:50 -0000 On 04/01/2008, Alfred Perlstein wrote: > You need to block/unblock signals or use sigwait. > > So basically your code will look something like: > defer_signals(); Interesting approach - should I also use it to ensure only one of the threads gets the signal? From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 12:01:55 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 990E316A420; Fri, 4 Jan 2008 12:01:55 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 88B8C13C44B; Fri, 4 Jan 2008 12:01:55 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 714351A4D83; Fri, 4 Jan 2008 03:59:27 -0800 (PST) Date: Fri, 4 Jan 2008 03:59:27 -0800 From: Alfred Perlstein To: Ivan Voras Message-ID: <20080104115927.GJ76698@elvis.mu.org> References: <20080104011821.GD76698@elvis.mu.org> <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> User-Agent: Mutt/1.4.2.3i 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: Fri, 04 Jan 2008 12:01:55 -0000 * Ivan Voras [080104 03:23] wrote: > On 04/01/2008, Alfred Perlstein wrote: > > > You need to block/unblock signals or use sigwait. > > > > So basically your code will look something like: > > > defer_signals(); > > Interesting approach - should I also use it to ensure only one of the > threads gets the signal? Certainly. -- - Alfred Perlstein From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 12:08:50 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 E0DDA16A417 for ; Fri, 4 Jan 2008 12:08:50 +0000 (UTC) (envelope-from gofdt-freebsd-threads@m.gmane.org) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mx1.freebsd.org (Postfix) with ESMTP id 9688713C45A for ; Fri, 4 Jan 2008 12:08:50 +0000 (UTC) (envelope-from gofdt-freebsd-threads@m.gmane.org) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JAlLv-0005Am-J8 for freebsd-threads@freebsd.org; Fri, 04 Jan 2008 12:08:43 +0000 Received: from lara.cc.fer.hr ([161.53.72.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Jan 2008 12:08:43 +0000 Received: from ivoras by lara.cc.fer.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Jan 2008 12:08:43 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-threads@freebsd.org From: Ivan Voras Date: Fri, 04 Jan 2008 13:08:30 +0100 Lines: 42 Message-ID: References: <20080104011821.GD76698@elvis.mu.org> <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> <20080104115927.GJ76698@elvis.mu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigED37D9FC0B1EBD04B33DB0C5" X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lara.cc.fer.hr User-Agent: Thunderbird 2.0.0.9 (X11/20070801) In-Reply-To: <20080104115927.GJ76698@elvis.mu.org> X-Enigmail-Version: 0.95.5 Sender: news 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: Fri, 04 Jan 2008 12:08:51 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigED37D9FC0B1EBD04B33DB0C5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Alfred Perlstein wrote: > * Ivan Voras [080104 03:23] wrote: >> On 04/01/2008, Alfred Perlstein wrote: >> >>> You need to block/unblock signals or use sigwait. >>> >>> So basically your code will look something like: >>> defer_signals(); >> Interesting approach - should I also use it to ensure only one of the >> threads gets the signal? >=20 > Certainly. Hmm: :/usr/include> man defer_signals No manual entry for defer_signals :/usr/include> grep -r defer_signals * -nothing found Where is defer_signals() ? --------------enigED37D9FC0B1EBD04B33DB0C5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) iD8DBQFHfiG/ldnAQVacBcgRAmQnAKCAD1V1Y3P/+vBoVw129QS0KM8RLwCfVyqx tKRUPMf3RHchyNEuvBI87xU= =oAPa -----END PGP SIGNATURE----- --------------enigED37D9FC0B1EBD04B33DB0C5-- From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 19:15:06 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 9A0B116A418; Fri, 4 Jan 2008 19:15:06 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 8B84613C448; Fri, 4 Jan 2008 19:15:06 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 532971A4D82; Fri, 4 Jan 2008 11:12:37 -0800 (PST) Date: Fri, 4 Jan 2008 11:12:37 -0800 From: Alfred Perlstein To: Ivan Voras Message-ID: <20080104191237.GK76698@elvis.mu.org> References: <20080104011821.GD76698@elvis.mu.org> <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> <20080104115927.GJ76698@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i 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: Fri, 04 Jan 2008 19:15:06 -0000 * Ivan Voras [080104 04:06] wrote: > Alfred Perlstein wrote: > > * Ivan Voras [080104 03:23] wrote: > >> On 04/01/2008, Alfred Perlstein wrote: > >> > >>> You need to block/unblock signals or use sigwait. > >>> > >>> So basically your code will look something like: > >>> defer_signals(); > >> Interesting approach - should I also use it to ensure only one of the > >> threads gets the signal? > > > > Certainly. > > Hmm: > > :/usr/include> man defer_signals > No manual entry for defer_signals > :/usr/include> grep -r defer_signals * > -nothing found > > Where is defer_signals() ? > That was psuedocode. You need to read up on signals, look at sigaction, pthread_sigmask, sigprocmask and such. -- - Alfred Perlstein From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 19:35:41 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 478FE16A46E; Fri, 4 Jan 2008 19:35:41 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id 038E613C468; Fri, 4 Jan 2008 19:35:40 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.2/8.14.2/NETPLEX) with ESMTP id m04JZdCC006866; Fri, 4 Jan 2008 14:35:39 -0500 (EST) X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.0 (mail.netplex.net [204.213.176.10]); Fri, 04 Jan 2008 14:35:39 -0500 (EST) Date: Fri, 4 Jan 2008 14:35:39 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Ivan Voras In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-threads@freebsd.org Subject: Re: Threads and signals X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jan 2008 19:35:41 -0000 On Thu, 3 Jan 2008, 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)? Yes, you don't want to call pthread_mutex_lock() (or really any other non-async-signal-safe function) from the signal handler. > How is this solved in general? By recursive mutexes? You can use sigwait() to wait for the signal and block it in all other threads, or you can use a pipe and write(2) to the pipe from the signal handler and have another reader thread handle the request. I suppose there are other ways, like sem_post(). -- DE From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 19:39:32 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 960E416A417 for ; Fri, 4 Jan 2008 19:39:32 +0000 (UTC) (envelope-from ivoras@gmail.com) Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.186]) by mx1.freebsd.org (Postfix) with ESMTP id 6779013C4CC for ; Fri, 4 Jan 2008 19:39:32 +0000 (UTC) (envelope-from ivoras@gmail.com) Received: by rv-out-0910.google.com with SMTP id l15so6685583rvb.43 for ; Fri, 04 Jan 2008 11:39:31 -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:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=rgRXO0BZiUEAmQuFvvUJ9RRTN2P/Tsj8JS/fbmGGYlo=; b=uFIvCRB07aWabLbkkqykeszE1jPBsPGg5L8Ve48/cPMVDdbLMega79E4ElE0NJ9t5ce61BUUvQ4xkM1xBMCx+5DfRulQIBAF+pOHclvJGQ6Obhn978R5gpVfmwhOQcsLdcd0HcfyUJz5lHbsJHN3yQW6d2puTGrFUr0PsTAYFmY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=ewZoWb0SEyhcktK5AzbbVFyjWVKljoXXOhNn9S7/O6WTIkyrMP7dUHDHnaHrgQMvSpkAT3vlnEnARQ052gtN3CmqAGvjAAZrR7401PhydJByaNMwG3RtlhMMm4budSEOFDAVmg4aO80nLiigq5XAoANhHj4xe+8kjuu/tbfw9Dg= Received: by 10.141.167.5 with SMTP id u5mr9109134rvo.71.1199475571791; Fri, 04 Jan 2008 11:39:31 -0800 (PST) Received: by 10.141.212.1 with HTTP; Fri, 4 Jan 2008 11:39:31 -0800 (PST) Message-ID: <9bbcef730801041139o4a54c069t772ab28aea7d3900@mail.gmail.com> Date: Fri, 4 Jan 2008 20:39:31 +0100 From: "Ivan Voras" Sender: ivoras@gmail.com To: "Alfred Perlstein" In-Reply-To: <20080104191237.GK76698@elvis.mu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080104011821.GD76698@elvis.mu.org> <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> <20080104115927.GJ76698@elvis.mu.org> <20080104191237.GK76698@elvis.mu.org> X-Google-Sender-Auth: 3148c4de7b85b2ea 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: Fri, 04 Jan 2008 19:39:32 -0000 On 04/01/2008, Alfred Perlstein wrote: > You need to read up on signals, look at sigaction, pthread_sigmask, > sigprocmask and such. Yes I do :) I missed pthread_sigmask because pthread(3) doesn't mention it. It's much clearer now that I know it exists. From owner-freebsd-threads@FreeBSD.ORG Fri Jan 4 20:01:23 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 7FDC316A41B; Fri, 4 Jan 2008 20:01:23 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 6EBDB13C442; Fri, 4 Jan 2008 20:01:23 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 113171A4D82; Fri, 4 Jan 2008 11:58:54 -0800 (PST) Date: Fri, 4 Jan 2008 11:58:54 -0800 From: Alfred Perlstein To: Ivan Voras Message-ID: <20080104195854.GL76698@elvis.mu.org> References: <20080104011821.GD76698@elvis.mu.org> <9bbcef730801040325y197aa7f6s134436dcc79d8aeb@mail.gmail.com> <20080104115927.GJ76698@elvis.mu.org> <20080104191237.GK76698@elvis.mu.org> <9bbcef730801041139o4a54c069t772ab28aea7d3900@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9bbcef730801041139o4a54c069t772ab28aea7d3900@mail.gmail.com> User-Agent: Mutt/1.4.2.3i 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: Fri, 04 Jan 2008 20:01:23 -0000 * Ivan Voras [080104 11:37] wrote: > On 04/01/2008, Alfred Perlstein wrote: > > > You need to read up on signals, look at sigaction, pthread_sigmask, > > sigprocmask and such. > > Yes I do :) > > I missed pthread_sigmask because pthread(3) doesn't mention it. It's > much clearer now that I know it exists. One more thing. I apologize if I came across too sternly or impatient, while I know the general way to do this, it's not fresh in my mind and I'm kind of busy. :) thank you, -- - Alfred Perlstein