From owner-freebsd-questions Wed Jan 12 12:54:16 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 0F9EB154B8 for ; Wed, 12 Jan 2000 12:54:11 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id VAA52051; Wed, 12 Jan 2000 21:54:10 +0100 (CET) (envelope-from olli) Date: Wed, 12 Jan 2000 21:54:10 +0100 (CET) Message-Id: <200001122054.VAA52051@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: Giving a sighandler more information X-Newsgroups: list.freebsd-questions In-Reply-To: <85gfv4$2ueb$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Laurence Berland wrote in list.freebsd-questions: > Oliver Fromme wrote: >> Seriously. You _must_ declare global variables which are >> accessed from a signal handler as ``volatile sig_atomic_t''. >> Everything else is _not_ guaranteed to work (and if it works, >> then it's just pure luck). > > Does this have something to do with the signal being caught while we're > in the signal routine? Am I on the right track? No. The problem is that a signal handler can be called at any time, basically, even in the midst of a memory access (depending on the platform). The standard guarantees that accesses to variables of type "sig_atomic_t" are always atomic (hence the name), i.e. they cannot be interrupted by a signal handler. The "volatile" qualifier makes sure that the compiler does not try certain optimizations on these variables, such as caching them in registers (which could also break signal handlers, because the contents of the actual variable might be incorrect if it's cached). Regards Oliver -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message