From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA27224; Fri, 6 Sep 2002 08:36:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA27042 for ; Fri, 6 Sep 2002 08:36:46 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from haut-marbuzet.homelinux.org (ALyon-101-1-4-15.abo.wanadoo.fr [217.128.172.15]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g866aj913733 for ; Fri, 6 Sep 2002 08:36:46 +0200 (MET DST) Received: from ldanthon by haut-marbuzet.homelinux.org with local (Exim 3.35 #1 (Debian)) id 17nCkS-0000Dc-00 for ; Fri, 06 Sep 2002 08:37:44 +0200 Date: Fri, 6 Sep 2002 08:37:44 +0200 From: Laure Danthony To: caml-list@inria.fr Subject: Re: [Caml-list] Unix.sleep in toplevel Message-ID: <20020906063744.GA830@haut-marbuzet.homelinux.org> Reply-To: Laure Danthony References: <200209060553.BAA07323@dewberry.cc.columbia.edu> <200209060626.CAA00217@hickory.cc.columbia.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200209060626.CAA00217@hickory.cc.columbia.edu> User-Agent: Mutt/1.3.28i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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