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