From: Markus Mottl <markus.mottl@gmail.com>
To: yminsky@cs.cornell.edu
Cc: SooHyoung Oh <shoh@compiler.kaist.ac.kr>,
Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Timeouts in Event module
Date: Mon, 24 Jan 2005 09:44:21 -0500 [thread overview]
Message-ID: <20050124144421.GA9726@quant3.janestcapital.quant> (raw)
In-Reply-To: <891bd339050123175618dc6acc@mail.gmail.com>
On Sun, 23 Jan 2005, Yaron Minsky wrote:
> Thanks. That looks quite useful. I suppose one could create a
> timed event by creating a channel and scheduling a callback to send on
> that channel. It seems like a bit of a hack (not your library, but
> the need to use such a mechanism to simulate timeouts), but it should
> do the job.
I remember having found the following solution, which I use in my projects
now, on the list a while ago:
let watchdog s v =
let ch = Event.new_channel () in
let watchdog_thread () =
Thread.delay s;
Event.sync (Event.send ch v) in
ignore (Thread.create watchdog_thread ());
Event.receive ch
let timed_sync s v event = Event.sync (Event.choose [event; watchdog s v])
You can use it e.g. as follows:
let thread_fun ch =
(* ... do something long ... *)
Event.sync (Event.send result) in
let ch = Event.new_channel () in
let tid = Thread.create thread_fun ch in
timed_sync 3.14 default_value (Event.receive ch)
If "thread_fun" doesn't send + synchronize a result within 3.14 seconds
on event channel "ch", then "default_value" will be returned, the result
otherwise.
Regards,
Markus
--
Markus Mottl markus.mottl@gmail.com http://www.ocaml.info
prev parent reply other threads:[~2005-01-24 14:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-23 13:49 Yaron Minsky
2005-01-24 0:53 ` [Caml-list] " SooHyoung Oh
2005-01-24 1:56 ` Yaron Minsky
2005-01-24 14:44 ` Markus Mottl [this message]
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=20050124144421.GA9726@quant3.janestcapital.quant \
--to=markus.mottl@gmail.com \
--cc=caml-list@inria.fr \
--cc=shoh@compiler.kaist.ac.kr \
--cc=yminsky@cs.cornell.edu \
/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).