caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Are refs volatile?
@ 2015-11-04 12:43 Richard W.M. Jones
  2015-11-04 13:18 ` Gerd Stolpmann
  2015-11-04 15:08 ` Gabriel Scherer
  0 siblings, 2 replies; 5+ messages in thread
From: Richard W.M. Jones @ 2015-11-04 12:43 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-04 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04 12:43 [Caml-list] Are refs volatile? Richard W.M. Jones
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

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).