Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Unix.sleep in toplevel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Laure Danthony <ldanthon@e...>
Subject: Re: [Caml-list] Unix.sleep in toplevel
Le Fri, Sep 06, 2002 at 02:26:40AM -0400, Oleg écrivait:
> Clarification: Unix.sleep doesn't work only after Graphics.open_graph has 
> been called, as it turned out (probably part of the same problem
> with threads + graphics)


So here is the solution X.Leroy's gave to me one year ago :

-----------------------------------
(caml-list)

[English summary: Laure observed that Unix.sleep returns early when
the graphics window is open.  Under Unix, the graphics library uses
signals for event processing, and on many Unix systems, Unix.sleep
returns early when interrupted by a signal.  Here is an alternate
implementation of sleep that is robust against signals.]

let mysleep n =
  let start = Unix.gettimeofday() in
  let rec delay t =
    try
      ignore (Unix.select [] [] [] t)
    with Unix.Unix_error(Unix.EINTR, _, _) ->
      let now = Unix.gettimeofday() in
      let remaining = start +. n -. now in
      if remaining > 0.0 then delay remaining in
  delay n

-----------------------------

Notice that n is a float instead of an int.

Hope this helps,

Laure Danthony

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners