From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA08332; Thu, 5 Sep 2002 13:31:25 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA07598 for ; Thu, 5 Sep 2002 13:31:24 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g85BUq125727; Thu, 5 Sep 2002 13:30:52 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA08092; Thu, 5 Sep 2002 13:30:52 +0200 (MET DST) Date: Thu, 5 Sep 2002 13:30:52 +0200 From: Xavier Leroy To: Lauri Alanko Cc: caml-list@inria.fr Subject: Re: [Caml-list] Inter-thread exceptions Message-ID: <20020905133052.C5343@pauillac.inria.fr> References: <20020903164851.A26567@kruuna.Helsinki.FI> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20020903164851.A26567@kruuna.Helsinki.FI>; from la@iki.fi on Tue, Sep 03, 2002 at 04:48:51PM +0300 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hello. > > How big a task would it be to implement asynchronous inter-thread > exceptions? In practice the feature would amount to a function: > > val raise_to : exn -> Thread.t -> unit > > This would be most handy for implementing eg. timeouts: just make a thread > that sleeps and raises an exception in the other thread when the time is > spent. Yes, this is a reasonable model for thread cancellation -- a lot better than Thread.kill, because the "victim" thread can catch the exception and perform cleanup actions like releasing mutexes. It's not hard to implement with bytecode-level threads (where Caml does the scheduling), but there is a major difficulty with system threads: if the target thread is blocked on a system call such as network I/O, it is extremely difficult to terminate the system call prematurely and have the target thread honor the exception immediately. (Under Unix, signals can allow this to some extent, but the semantics of signals in POSIX threads prevents directing a signal to a particular thread. POSIX thread cancellation could perhaps be abused to deal with this situation, however. Under Windows, the situation is even worse...) So, the only easily implementable behavior is that the target thread of a "raise_to" operation can delay the processing of the exception until it returns from a system call. But this behavior is nearly useless... - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners