caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Laure Danthony <ldanthon@ens-lyon.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Unix.sleep in toplevel
Date: Fri, 6 Sep 2002 08:37:44 +0200	[thread overview]
Message-ID: <20020906063744.GA830@haut-marbuzet.homelinux.org> (raw)
In-Reply-To: <200209060626.CAA00217@hickory.cc.columbia.edu>

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


      reply	other threads:[~2002-09-06  6:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-06  5:53 Oleg
2002-09-06  6:26 ` Oleg
2002-09-06  6:37   ` Laure Danthony [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=20020906063744.GA830@haut-marbuzet.homelinux.org \
    --to=ldanthon@ens-lyon.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).