src/Pure/Concurrent/synchronized_sequential.ML
author wenzelm
Sun, 28 Dec 2014 22:10:09 +0100
changeset 59195 f8588372d70e
parent 59160 faaedc8222c8
permissions -rw-r--r--
back to full synchronization (cf. eb3e399f5b9f);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32816
5db89f8d44f3 more official status of sequential implementations;
wenzelm
parents: 32738
diff changeset
     1
(*  Title:      Pure/Concurrent/synchronized_sequential.ML
32736
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
32816
5db89f8d44f3 more official status of sequential implementations;
wenzelm
parents: 32738
diff changeset
     4
Sequential version of state variables -- plain refs.
32736
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
32816
5db89f8d44f3 more official status of sequential implementations;
wenzelm
parents: 32738
diff changeset
    10
abstype 'a var = Var of 'a Unsynchronized.ref
5db89f8d44f3 more official status of sequential implementations;
wenzelm
parents: 32738
diff changeset
    11
with
32736
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    12
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32736
diff changeset
    13
fun var _ x = Var (Unsynchronized.ref x);
32736
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    14
fun value (Var var) = ! var;
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    15
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    16
fun timed_access (Var var) _ f =
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    17
  (case f (! var) of
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    18
    SOME (y, x') => (var := x'; SOME y)
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    19
  | NONE => Thread.unavailable ());
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    20
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    21
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
    22
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    23
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
    24
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
    25
f126e68d003d Dummy version of state variables -- plain refs for sequential access.
wenzelm
parents:
diff changeset
    26
end;
40449
9c390868d255 added general Synchronized.counter convenience;
wenzelm
parents: 35015
diff changeset
    27
32816
5db89f8d44f3 more official status of sequential implementations;
wenzelm
parents: 32738
diff changeset
    28
end;