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 MAA08742; Fri, 17 Aug 2001 12:00:06 +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 MAA08810 for ; Fri, 17 Aug 2001 12:00:05 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7HA04L15030 for ; Fri, 17 Aug 2001 12:00:04 +0200 (MET DST) Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) id MAA22444 for caml-list@inria.fr; Fri, 17 Aug 2001 12:00:04 +0200 Date: Fri, 17 Aug 2001 12:00:04 +0200 From: Markus Mottl To: caml-list@inria.fr Subject: Re: [Caml-list] How to make a delay ? Message-ID: <20010817120003.A19392@fichte.ai.univie.ac.at> References: <20010817061534.A14359@darling.home.br> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010817061534.A14359@darling.home.br>; from romildo@uber.com.br on Fri, Aug 17, 2001 at 06:15:34 -0300 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 17 Aug 2001, Jos? Romildo Malaquias wrote: > I am need to control the time under a program I am writing, in order > to simulate a real-time situation. I just need a function that suspends > the program execution for a given time, in miliseconds precision. You can use timers and signals to do this, e.g.: --------------------------------------------------------------------------- open Sys open Unix open Printf let _ = set_signal sigalrm (Signal_handle (fun _ -> ())); let timer = 3.14159 in let expected_time = gettimeofday () +. timer in ignore (setitimer ITIMER_REAL { it_interval = 0.0; it_value = timer }); pause (); printf "Precision: %f\n" (abs_float (gettimeofday () -. expected_time)) --------------------------------------------------------------------------- Depending on the type and load of your system, you can achieve precision in the range of milliseconds. Regards, Markus Mottl -- Markus Mottl markus@oefai.at Austrian Research Institute for Artificial Intelligence http://www.oefai.at/~markus ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr