From: Xavier Leroy <xavier.leroy@inria.fr>
To: Lauri Alanko <la@iki.fi>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Inter-thread exceptions
Date: Thu, 5 Sep 2002 13:30:52 +0200 [thread overview]
Message-ID: <20020905133052.C5343@pauillac.inria.fr> (raw)
In-Reply-To: <20020903164851.A26567@kruuna.Helsinki.FI>; from la@iki.fi on Tue, Sep 03, 2002 at 04:48:51PM +0300
> 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
next prev parent reply other threads:[~2002-09-05 11:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-03 13:48 Lauri Alanko
2002-09-04 14:43 ` Sven LUTHER
2002-09-04 15:30 ` Florian Douetteau
2002-09-05 11:30 ` Xavier Leroy [this message]
2002-09-06 18:22 ` Dmitry Bely
2002-09-09 14:15 ` Xavier Leroy
2002-09-11 20:41 ` Dmitry Bely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020905133052.C5343@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=la@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).