* [Caml-list] signals & threading
@ 2006-02-24 12:09 Jonathan Roewen
0 siblings, 0 replies; only message in thread
From: Jonathan Roewen @ 2006-02-24 12:09 UTC (permalink / raw)
To: OCaml
Here's some example code once posted on the list to have a timeout.
let set_timer tsecs =
ignore (Unix.setitimer Unix.ITIMER_REAL
{ Unix.it_interval = 0.0; Unix.it_value = tsecs })
exception Timeout
let handle_sigalrm signo =
print_string "Continue for how long? "; flush stdout;
let f = read_float() in
if f <= 0.0
then raise Timeout
else set_timer f
let continueq f arg tsecs defaultval =
let oldsig = Sys.signal Sys.sigalrm (Sys.Signal_handle handle_sigalrm) in
try
set_timer tsecs;
let res = f arg in
set_timer 0.0;
Sys.set_signal Sys.sigalrm oldsig;
res
with Timeout ->
Sys.set_signal Sys.sigalrm oldsig;
defaultval
Now, my question is: what happens with multiple threads? The exception
is raised in whatever thread is currently running? Is there also no
control over such behaviour?
Jonathan
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-02-24 12:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-24 12:09 [Caml-list] signals & threading Jonathan Roewen
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).