From owner-freebsd-threads@FreeBSD.ORG Sun Mar 21 17:07:52 2010 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 4A37C106564A for ; Sun, 21 Mar 2010 17:07:52 +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 08C488FC08 for ; Sun, 21 Mar 2010 17:07:51 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.4/8.14.4/NETPLEX) with ESMTP id o2LH7oHH019778; Sun, 21 Mar 2010 13:07:50 -0400 (EDT) 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.2.2 (mail.netplex.net [204.213.176.10]); Sun, 21 Mar 2010 13:07:50 -0400 (EDT) Date: Sun, 21 Mar 2010 13:07:50 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Pierre-Luc Drouin In-Reply-To: <4BA64260.5000009@pldrouin.net> Message-ID: References: <4BA64260.5000009@pldrouin.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-threads@freebsd.org Subject: Re: Portable Conditional Wait for Inter-Process? 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: Sun, 21 Mar 2010 17:07:52 -0000 On Sun, 21 Mar 2010, Pierre-Luc Drouin wrote: > Hi, > > I am looking for a portable solution to put a process into a timed wait (a la > pthread_cond_timedwait) such that it can be waken up by another process using > something similar to pthread_cond_broadcast (there might be many waiters). I > guess shared pthread condition variables are not supported by FreeBSD, right? > Is there a portable way to do this? The only solution I can think of right > now is to use alarm and sigwait on the waiters side and kill(wpid,SIGCONT) > on the other side with a list of pids. Yeah, shared mutexes and CVs are not yet supported by FreeBSD. You can use sigtimedwait() to conditionally sleep and kill on the other side, but with caveats: o Only one thread per process can be woken with sigwait() and friends o You must ensure that no other threads (other than the waiter) have the "wake" signal unmasked. You might consider using killpg() to send a signal to multiple processes in a process group. FreeBSD current (9.0) recently added support for shared semapores, so you could give those a try. You might be able to use sem_timedwait() instead of pthread_cond_timedwait() depending on your needs, but you are limited to waking only one thread at a time via sem_post(). You could also have a pipe or domain socket between the sender and each waiting processes. I suppose you could use aio_write() on the sender side to write to selected file descriptors with one operation. The waiters would be using poll() or select() with a timeout. -- DE