src/Pure/ML-Systems/unsynchronized.ML
author blanchet
Mon, 22 Aug 2011 15:02:45 +0200
changeset 44403 15160cdc4688
parent 39616 8052101883c3
permissions -rw-r--r--
precisely distinguish between universal and existential quantifiers, instead of assuming the worst (universal), for monotonicity analysis

(*  Title:      Pure/ML-Systems/unsynchronized.ML
    Author:     Makarius

Raw ML references as unsynchronized state variables.
*)

structure Unsynchronized =
struct

datatype ref = datatype ref;

val op := = op :=;
val ! = !;

fun change r f = r := f (! r);
fun change_result r f = let val (x, y) = f (! r) in r := y; x end;

fun inc i = (i := ! i + (1: int); ! i);
fun dec i = (i := ! i - (1: int); ! i);

fun setmp flag value f x =
  uninterruptible (fn restore_attributes => fn () =>
    let
      val orig_value = ! flag;
      val _ = flag := value;
      val result = Exn.capture (restore_attributes f) x;
      val _ = flag := orig_value;
    in Exn.release result end) ();

end;