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] 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: 2002-09-06 (06:36)
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 :


[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 =
      ignore ( [] [] [] 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 Archives:
Bug reports: FAQ:
Beginner's list: