caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rich@annexia.org>
To: caml-list@inria.fr
Subject: [Caml-list] Are refs volatile?
Date: Wed, 4 Nov 2015 12:43:21 +0000	[thread overview]
Message-ID: <20151104124321.GA25230@annexia.org> (raw)

Some code I wrote recently does:

  let quit = ref false in
  let set_quit _ = quit := true in
  Sys.set_signal Sys.sigint (Sys.Signal_handle set_quit);
  Sys.set_signal Sys.sigquit (Sys.Signal_handle set_quit);

and later on (where `tasks' is a list of long-running tasks):

  List.iter (
    fun task ->
      if not !quit then task ();
  ) tasks;

This works fine.  My question is, could a change to the compiler in
future cause the reference to !quit to be optimized away?  And if so,
is there a way to mark it as "volatile" (in the C sense)?

Rich.

-- 
Richard Jones
Red Hat

             reply	other threads:[~2015-11-04 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-04 12:43 Richard W.M. Jones [this message]
2015-11-04 13:18 ` Gerd Stolpmann
2015-11-04 15:08 ` Gabriel Scherer
2015-11-04 15:23   ` Richard W.M. Jones
2015-11-04 15:56     ` Pierre Chambart

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=20151104124321.GA25230@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@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).