caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Timeouts in Event module
@ 2005-01-23 13:49 Yaron Minsky
  2005-01-24  0:53 ` [Caml-list] " SooHyoung Oh
  0 siblings, 1 reply; 4+ messages in thread
From: Yaron Minsky @ 2005-01-23 13:49 UTC (permalink / raw)
  To: Caml Mailing List

Does anyone know of a way of achieving timeouts using OCaml's Event
module?  Reppy's Concrrent ML has timeout and attime events which
cover for that need.  I'm wondering if there is some other way of
implementing this using Event, or if this is just a missing feature.

Thanks,
Yaron


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Timeouts in Event module
  2005-01-23 13:49 Timeouts in Event module Yaron Minsky
@ 2005-01-24  0:53 ` SooHyoung Oh
  2005-01-24  1:56   ` Yaron Minsky
  0 siblings, 1 reply; 4+ messages in thread
From: SooHyoung Oh @ 2005-01-24  0:53 UTC (permalink / raw)
  To: yminsky; +Cc: Caml Mailing List


I implemented a timer library.
Look http://pllab.kaist.ac.kr/~shoh/ocaml/libs/timer/
This library uses Sys module and unix, thread library.


Yaron Minsky 쓴 글:

>Does anyone know of a way of achieving timeouts using OCaml's Event
>module?  Reppy's Concrrent ML has timeout and attime events which
>cover for that need.  I'm wondering if there is some other way of
>implementing this using Event, or if this is just a missing feature.
>
>Thanks,
>Yaron
>
>_______________________________________________
>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
>
>  
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Timeouts in Event module
  2005-01-24  0:53 ` [Caml-list] " SooHyoung Oh
@ 2005-01-24  1:56   ` Yaron Minsky
  2005-01-24 14:44     ` Markus Mottl
  0 siblings, 1 reply; 4+ messages in thread
From: Yaron Minsky @ 2005-01-24  1:56 UTC (permalink / raw)
  To: SooHyoung Oh; +Cc: Caml Mailing List

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.

y


On Mon, 24 Jan 2005 09:53:21 +0900, SooHyoung Oh
<shoh@compiler.kaist.ac.kr> wrote:
> 
> I implemented a timer library.
> Look http://pllab.kaist.ac.kr/~shoh/ocaml/libs/timer/
> This library uses Sys module and unix, thread library.
> 
> Yaron Minsky 쓴 글:
> 
> >Does anyone know of a way of achieving timeouts using OCaml's Event
> >module?  Reppy's Concrrent ML has timeout and attime events which
> >cover for that need.  I'm wondering if there is some other way of
> >implementing this using Event, or if this is just a missing feature.
> >
> >Thanks,
> >Yaron
> >
> >_______________________________________________
> >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
> >
> >
> >
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Timeouts in Event module
  2005-01-24  1:56   ` Yaron Minsky
@ 2005-01-24 14:44     ` Markus Mottl
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Mottl @ 2005-01-24 14:44 UTC (permalink / raw)
  To: yminsky; +Cc: SooHyoung Oh, Caml Mailing List

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-24 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-23 13:49 Timeouts in Event module 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 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).