From: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
To: caml-list@yquem.inria.fr
Subject: Has the thread cancellation problem evolved ?
Date: Sat, 25 Aug 2007 15:58:47 +0200 [thread overview]
Message-ID: <9FA25C33-04DD-46BD-8959-873DDD2FFF82@epfl.ch> (raw)
Hello everybody,
I would like to raise again the problem of portable thread
cancellation. The potential coming (?) of native dynamic linking
brings the stunning perspective of type-safe, native, plugins.
However to be able to use this in conjunction with user interfaces
(ui) or in a malicious environment it becomes even more acute to be
able to monitor/sandbox the execution of functions to avoid
application hangs.
Thread cancellation allows to invoke an arbitrary function f on a
thread and stop its execution before completion, without introducing
checks for conditions in f -- rewriting every function to do that
goes against separation of concerns and malicious code could just
ignore such conditions.
Xavier Leroy mentioned many time [1,2,3] that "Thread.kill" is not an
option. The argument is that this function is "unsafe" (not in the
typical sense) because the victim may be holding ressources and it
should be given the opportunity to release them before dying. As such
this function is not implemented in the native thread library and
will never be (btw. it is still not deprecated in 3.10). Other
solutions have been proposed [4,5]. [5] by Gerd Stolpmann is
portable. Note however that neither solution will work with
uncooperative threads, i.e. those that never perform any system call
or trigger the gc [7].
In this [6] message Xavier Leroy acknowledges that having a function
"Thread.raise_in : exn -> Thread.t -> unit" to raise an exception in
the given thread is a reasonable alternative to "Thread.kill".
However the same message points out that this would be difficult to
implement for native threads that are blocked on system calls and
concludes :
"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..."
While it wouldn't (or would it ?) solve the problem of uncooperative
threads and hence be useless in a malicious environment, the "easy
implementation" would be useful to monitor cooperative computations
in general -- well those that do not block on system calls, but in a
ui there may be many of these.
I would appreciate having "Thread.raise_in" implemented, with the
system call caveat properly documented, instead of having to resort
to [5]. There is no feature request about this in the bug tracker.
Before filling a potentially useless one I would like to know what
you think about these problems and if there are things I have missed.
Best,
Daniel
P.S. If your computations need to interact with the ui, forking is
out of question.
[1] http://caml.inria.fr/pub/ml-archives/caml-list/
2000/05/4cf198c2f8dbf533cde462f2c65cf827.fr.html
[2] http://caml.inria.fr/pub/ml-archives/caml-list/
2002/10/740fa6facb5981e6dc94c4b7d13ea7ed.fr.html
[3] http://caml.inria.fr/pub/ml-archives/caml-list/
2003/05/8d9e6f406983d144111852cb7367ebc7.fr.html
[4] http://caml.inria.fr/pub/ml-archives/caml-list/
2005/12/52715b2ecd818ac61af3ffb34e914ec1.fr.html
[5] http://caml.inria.fr/pub/ml-archives/caml-list/
2005/11/71f680d0defd7ad890587f2b6d339ab5.fr.html
[6] http://caml.inria.fr/pub/ml-archives/caml-list/
2002/09/36902268c9eb832e0042bf74426e14d2.fr.html
[7] The difference between cooperative and uncooperative threads can
be seen by compiling the following two programs to _native_ code. The
first one loops forever while the other doesn't (because it allocates).
--
let () =
ignore (Thread.create (fun () -> while true do ignore (1 + 2)
done) ());
Thread.delay 1.
--
let () =
ignore (Thread.create (fun () -> while true do ignore (1. +. 2.)
done) ());
Thread.delay 1.
--
next reply other threads:[~2007-08-25 13:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-25 13:58 Daniel Bünzli [this message]
2007-08-25 15:29 ` [Caml-list] " skaller
2007-08-26 23:47 ` Daniel Bünzli
2007-08-27 0:18 ` Till Varoquaux
2007-08-27 4:38 ` skaller
2007-08-27 10:12 ` Daniel Bünzli
2007-08-27 11:28 ` skaller
2007-08-27 11:49 ` Jon Harrop
2007-08-27 12:24 ` Daniel Bünzli
2007-08-27 12:38 ` Jon Harrop
2007-08-27 13:09 ` Daniel Bünzli
2007-08-27 14:27 ` skaller
2007-08-27 7:55 ` Markus E L
2007-08-27 23:33 ` Gerd Stolpmann
2007-08-28 9:26 ` Daniel Bünzli
2007-08-28 11:42 ` Gerd Stolpmann
2007-08-28 14:46 ` Daniel Bünzli
2007-08-28 14:23 ` Gordon Henriksen
2007-08-28 14:35 ` Brian Hurt
2007-08-28 14:44 ` Daniel Bünzli
2007-08-28 14:54 ` Robert Fischer
2007-08-28 15:12 ` Brian Hurt
2007-08-28 15:32 ` Gordon Henriksen
2007-08-28 15:40 ` skaller
2007-08-29 8:12 ` Lionel Elie Mamane
2007-08-28 15:00 ` Gordon Henriksen
2007-08-25 15:44 ` skaller
2007-08-26 23:24 ` Alain Frisch
2007-08-25 15:57 ` Gordon Henriksen
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=9FA25C33-04DD-46BD-8959-873DDD2FFF82@epfl.ch \
--to=daniel.buenzli@epfl.ch \
--cc=caml-list@yquem.inria.fr \
/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