caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas George <nicolas.george@ens.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Timeouts and event
Date: Fri, 14 Sep 2001 00:04:31 +0200	[thread overview]
Message-ID: <20010914000431.A3510@aimlin> (raw)
In-Reply-To: <3BA105FB.7500FD0@cmu.edu>; from ecc@cmu.edu on Thu, Sep 13, 2001 at 03:16:11PM -0400

Le jeudi 13 septembre 2001 à 15:16, Eric C. Cooper a écrit :
> You can do this nicely using a "watchdog event" that produces a value
> after a timeout.

Ok, you create a new thread, who will only send the event after the
timeout. I am always a bit reluctant in creating new threads, especially if
I use system threads. If there were some builtin timeout event, it would be
great. And since we are in feature wish, event corresponding to wait_read
and wait_write.

> let watchdog seconds v =
>   let channel = Event.new_channel () in
>   let watchdog_thread () =
>     Thread.delay seconds;
>     Event.sync (Event.send channel v)
>   in
>   ignore (Thread.create watchdog_thread ());
>   Event.receive channel

I would write the two last lines like that:

let child = Thread.create watchdog_thread () in
let event = Event.receive channel in
Event.wrap_abort event ~f:(fun () -> Thread.kill child)

Aargh, Thread.kill does not exist with system threads!
(I see one solution, which is to start a new thread that will only sync the
event, but I think it is a waste.)
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      reply	other threads:[~2001-09-13 22:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-13  9:35 Nicolas George
2001-09-13 19:16 ` Eric C. Cooper
2001-09-13 22:04   ` Nicolas George [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=20010914000431.A3510@aimlin \
    --to=nicolas.george@ens.fr \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).