src/Pure/Concurrent/synchronized_dummy.ML
author wenzelm
Mon, 28 Sep 2009 23:51:13 +0200
changeset 32736 f126e68d003d
child 32738 15bb09ca0378
permissions -rw-r--r--
Dummy version of state variables -- plain refs for sequential access.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32736
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Concurrent/synchronized_dummy.ML
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     3
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     4
Dummy version of state variables -- plain refs for sequential access.
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     5
*)
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     6
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     7
structure Synchronized: SYNCHRONIZED =
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     8
struct
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
     9
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    10
datatype 'a var = Var of 'a ref;
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    11
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    12
fun var _ x = Var (ref x);
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    13
fun value (Var var) = ! var;
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    14
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    15
fun timed_access (Var var) _ f =
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    16
  (case f (! var) of
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    17
    SOME (y, x') => (var := x'; SOME y)
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    18
  | NONE => Thread.unavailable ());
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    19
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    20
fun guarded_access var f = the (timed_access var (K NONE) f);
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    21
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    22
fun change_result var f = guarded_access var (SOME o f);
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    23
fun change var f = change_result var (fn x => ((), f x));
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    24
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    25
end;