Browse thread
[Caml-list] How to make a delay ?
-
José_Romildo_Malaquias
- Daniel de Rauglaudre
- Markus Mottl
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Markus Mottl <markus@m...> |
| Subject: | Re: [Caml-list] How to make a delay ? |
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