author | wenzelm |
Tue, 29 Dec 2015 16:23:34 +0100 | |
changeset 61959 | 364007370bb7 |
parent 52537 | 4b5941730bd8 |
child 62920 | a5853334c179 |
permissions | -rw-r--r-- |
(* Title: Pure/Concurrent/counter.ML Author: Makarius Synchronized counter for unique identifiers > 0. NB: ML ticks forwards, JVM ticks backwards. *) signature COUNTER = sig val make: unit -> unit -> int end; structure Counter: COUNTER = struct fun make () = let val counter = Synchronized.var "counter" (0: int); fun next () = Synchronized.change_result counter (fn i => let val j = i + (1: int) in (j, j) end); in next end; end;