<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/9f0ca6903d5847a3857caae30a564264"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-24T12:09:36"
  subject="[Caml-list] signals &amp; threading"
  prev="2006/02/08aa1f53f8a7c6e0d96156f8e4d2ca20"
  next="2006/02/1245b24d768342c39d5fe0d071df339f"
  prev-thread="2006/02/579a51a1051b15f49ce25ed80aa0704c"
  next-thread="2006/02/1640d4314b4423c9ca49c8e5bba9d00a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] signals &amp; threading">
<msg 
  url="2006/02/9f0ca6903d5847a3857caae30a564264"
  from="Jonathan Roewen &lt;jonathan.roewen@g...&gt;"
  author="Jonathan Roewen"
  date="2006-02-24T12:09:36"
  subject="[Caml-list] signals &amp; threading">
</msg>
</thread>

<contents>
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 &lt;= 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 -&gt;
    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

</contents>

</message>

