From owner-freebsd-hackers Sat Jun 20 14:56:50 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA14043 for freebsd-hackers-outgoing; Sat, 20 Jun 1998 14:56:50 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from cimlogic.com.au (cimlog.lnk.telstra.net [139.130.51.31]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA14033 for ; Sat, 20 Jun 1998 14:56:45 -0700 (PDT) (envelope-from jb@cimlogic.com.au) Received: (from jb@localhost) by cimlogic.com.au (8.8.8/8.8.7) id IAA24243; Sun, 21 Jun 1998 08:03:45 +1000 (EST) (envelope-from jb) From: John Birrell Message-Id: <199806202203.IAA24243@cimlogic.com.au> Subject: Re: Signals in POSIX threads In-Reply-To: from =?ISO-8859-1?Q?Dag=2DErling_Coidan_Sm=F8rgrav?= at "Jun 20, 98 12:09:03 pm" To: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?=) Date: Sun, 21 Jun 1998 08:03:44 +1000 (EST) Cc: smoergrd@oslo.geco-prakla.slb.com, hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Dag-Erling Coidan Smørgrav wrote: > What bothers me is data sharing. Since I don't know which thread will > run the signal handler, I don't know if it will be necessary to > protect the data it uses with a mutex or if I can access it safely. I > don't much like the idea of spin-waiting on a mutex lock inside a > signal handler, either. > > If I set all threads except the main() thread to block a specific > signal (say, SIGHUP), and install a handler for it, will that ensure > that it runs in the main() thread or will it just disappear down a > black hole nine out of ten times? The easiest way to handle this (IMO) is to create a pipe and have the signal handler just write a character to the pipe for each non-nasty signal that it receives. Then have a thread do a blocking read on the pipe. This way you do next to nothing in the signal handler and the thread that reads the pipe can block on whatever mutexes it needs to get access to the data structures. It can then signal condition variables for any other threads that need to deal with th changed data. > -- > One two, one two, one two. > > ¹ I'm working on real-time visualization of hydrophone data onboard > seismological exploration vessels. That brings back memories. I use to work for Schlumberger as a wireline engineer. 8-) -- John Birrell - jb@cimlogic.com.au; jb@freebsd.org http://www.cimlogic.com.au/ CIMlogic Pty Ltd, GPO Box 117A, Melbourne Vic 3001, Australia +61 418 353 137 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message