From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Has the thread cancellation problem evolved ?
Date: Mon, 27 Aug 2007 02:18:27 +0200 [thread overview]
Message-ID: <9d3ec8300708261718x7b62395cm70fdce72a47c592@mail.gmail.com> (raw)
In-Reply-To: <D6A4296A-A9A2-4621-A6F7-7AD58E8764EB@epfl.ch>
Hmm,
I have a very partial answer. I had to implement timeouts on blocking
calls recently I had to resort to alarms. You seem to be well
documented so I don't think this will be new to you. It might however
be useful to less seasoned hackers.
Here is the sample code:
exception Timeout
let timeout timeout f arg=
let resChan=Event.new_channel () in
let res=Event.receive resChan in
let _= Thread.create begin
fun () ->
Unix.alarm timeout;
Sys.signal Sys.sigalrm (Sys.Signal_handle begin
fun _ ->
Event.sync(Event.send resChan None);
Thread.exit ()
end);
let computation=Event.send resChan (Some (f arg)) in
Event.sync(computation)
end ()
in
match Event.sync(res) with
| Some e -> e
| None -> raise Timeout
let _ =
let r=timeout 1 (fun a -> Thread.delay 1.5; a) "arg" in
print_string r
As a side note I thinks Threads.raise_in would be awesome, it might be
hard to add in the language though...
Till
On 8/27/07, Daniel Bünzli <daniel.buenzli@epfl.ch> wrote:
>
> Le 25 août 07 à 17:29, skaller a écrit :
>
> > There is something I don't understand here.
>
> What you don't understand is that ocaml has a runtime system which
> leaves some room for designing around what exists at the os level.
>
> > If the source of the problem is a blocking operation, the solution
> > is simple: don't use blocking operations!
>
> This is not the source of the problem. What I want is to allow users
> to initiate and cancel computations whenever they want. Computations
> can be lengthy even tough they do not invoke a blocking operation.
>
> The problem is that libraries are not -- and should not -- be
> designed with cancellation in mind, say every function has an
> optional parameter that allows to stop the computation. Cancellation
> should be a service of the runtime system, and denying its usefulness
> because it could be misused makes no sense, I can also open a file
> and never close it, it is a matter of programming discipline.
>
> Daniel
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
next prev parent reply other threads:[~2007-08-27 0:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-25 13:58 Daniel Bünzli
2007-08-25 15:29 ` [Caml-list] " skaller
2007-08-26 23:47 ` Daniel Bünzli
2007-08-27 0:18 ` Till Varoquaux [this message]
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=9d3ec8300708261718x7b62395cm70fdce72a47c592@mail.gmail.com \
--to=till.varoquaux@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=daniel.buenzli@epfl.ch \
/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