Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] signals and exceptions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andy Chou <acc@C...>
Subject: [Caml-list] signals and exceptions
Can I safely throw an exception inside a signal handler, for the purposes 
of timeout?  For example:

exception Timeout

Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ -> raise Timeout));
    (try
       ignore(Unix.alarm 5);
       work();
       if Unix.alarm 0 == 0 then
         Unix.pause()
     with Timeout -> printf "TIMEOUT\n");
Sys.set_signal Sys.sigalrm Sys.Signal_ignore;

Will there be an GC problems, etc?  I've noticed that a program that uses
this idiom non-deterministically seg faults.

-Andy
-------------------
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