From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA26382 for caml-redistribution; Wed, 19 May 1999 19:46:08 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA17672 for ; Tue, 18 May 1999 18:12:49 +0200 (MET DST) Received: from morgane.oleane.net (Morgane.OLEANE.Net [194.2.1.9]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id SAA08736 for ; Tue, 18 May 1999 18:12:47 +0200 (MET DST) Received: from tom.oleane.net (tom.oleane.net [194.2.28.14]) by morgane.oleane.net with ESMTP id SAA06436; Tue, 18 May 1999 18:12:43 +0200 Received: from hoedic.trusted-logic.fr (dyn-1-2-041.Def.dialup.oleane.fr [195.25.27.41]) by tom.oleane.net (8.8.8/8.8.8) with ESMTP id SAA09319; Tue, 18 May 1999 18:12:31 +0200 Received: (from xleroy@localhost) by hoedic.trusted-logic.fr (8.8.7/8.8.7) id SAA24999; Tue, 18 May 1999 18:10:20 +0200 Date: Tue, 18 May 1999 18:10:20 +0200 From: Xavier Leroy To: Joerg Czeranski Cc: caml-list@inria.fr Subject: Re: more patches (for Unix signal mask) Message-ID: <19990518181020.A24993@hoedic.trusted-logic.fr> References: <5v6tgd6vv$19X$1@joerch.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.4us In-Reply-To: <5v6tgd6vv$19X$1@joerch.org>; from Joerg Czeranski on Sun, May 16, 1999 at 11:40:56PM +0200 Sender: weis > I had a look at the web interface to Caml's CVS repository > and noticed that my previous patches are already incorporated > (except for byterun/intern.c, but I'm not so sure that it makes > a difference at all). :-) I'm still not sure whether the casts are really needed or whether the Dec C compiler is wrong in emitting a warning. > I replaced all sigsetjmp() calls with _setjmp() calls (setjmp() is > allowed to modify the signal mask, too, as per Single Unix Spec v2) > and handled jumps out of signal handlers separately. That's an interesting idea; I'll have to think about it. By the way, you can just do sigsetjmp(..., 0) if you don't want the signal mask to be saved and restored; this is more portable than _setjmp. > Exceptions on the other hand go straight up the stack until they find > a handler, and then *immediately* invalidate the handler. > In a non-pure programming language like O'Caml this creates unavoidable > race conditions: > let resource = acquire () in > try > use resource; > release resource > with e -> > release resource; > raise e > "release" is never called if two exceptions arrive at virtually > the same time, and neither if an exception arrives after the call > to "acquire", but before the "try". Yes, asynchronous exceptions (such as those generated from a signal handler) are very hard to use because of this. The programming idiom you showed above is safe for synchronous exceptions (exceptions that can only be raised by "use resource"), however. My take on this is that exceptions as they are implemented now are just fine as a non-local control structure inside a sequential program, but that something else is needed for multithreaded and signal-based processing. The thread cancellation model of Posix threads is an interesting example of how inter-thread asynchronous notifications can be made safe. Regards, - Xavier Leroy