Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Timeouts and event
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-09-13 (22:41)
From: Nicolas George <>
Subject: Re: [Caml-list] Timeouts and event
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:  FAQ:
To unsubscribe, mail  Archives: