Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jun 1998 08:03:44 +1000 (EST)
From:      John Birrell  <jb@cimlogic.com.au>
To:        dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?=)
Cc:        smoergrd@oslo.geco-prakla.slb.com, hackers@FreeBSD.ORG
Subject:   Re: Signals in POSIX threads
Message-ID:  <199806202203.IAA24243@cimlogic.com.au>
In-Reply-To: <xzpogvotmf4.fsf@hrotti.ifi.uio.no> from =?ISO-8859-1?Q?Dag=2DErling_Coidan_Sm=F8rgrav?= at "Jun 20, 98 12:09:03 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806202203.IAA24243>