caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: OCaml <caml-list@yquem.inria.fr>
Subject: [Caml-list] signals & threading
Date: Sat, 25 Feb 2006 01:09:35 +1300	[thread overview]
Message-ID: <ad8cfe7e0602240409h2cac1c08r4bad782a10d36f02@mail.gmail.com> (raw)

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


                 reply	other threads:[~2006-02-24 12:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad8cfe7e0602240409h2cac1c08r4bad782a10d36f02@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).