From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: "Richard W.M. Jones" <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Are refs volatile?
Date: Wed, 04 Nov 2015 14:18:48 +0100 [thread overview]
Message-ID: <1446643128.3000.11.camel@thinkpad.lan.sumadev.de> (raw)
In-Reply-To: <20151104124321.GA25230@annexia.org>
[-- Attachment #1: Type: text/plain, Size: 1384 bytes --]
Am Mittwoch, den 04.11.2015, 12:43 +0000 schrieb Richard W.M. Jones:
> 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)?
Interesting question. My guess is that it is much harder to optimize
side-effects in the presence of closures, and that it is fairly unlikely
that anybody attempts this. In this piece of code, you must be sure that
[task] doesn't set [quit], but this ref can be well hidden, and the
analysis needed to figure this out seems to be complicated.
Gerd
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de
My OCaml site: http://www.camlcity.org
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
------------------------------------------------------------
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-11-04 13:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 12:43 Richard W.M. Jones
2015-11-04 13:18 ` Gerd Stolpmann [this message]
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=1446643128.3000.11.camel@thinkpad.lan.sumadev.de \
--to=info@gerd-stolpmann.de \
--cc=caml-list@inria.fr \
--cc=rich@annexia.org \
/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