src/Pure/Concurrent/counter.ML
author wenzelm
Thu, 29 Jan 2015 15:21:16 +0100
changeset 59468 fe6651760643
parent 52537 4b5941730bd8
child 62920 a5853334c179
permissions -rw-r--r--
explicit threads_stack_limit (for recent Poly/ML SVN versions), which leads to soft interrupt instead of exhaustion of virtual memory, which is particularly relevant for the bigger address space of x86_64;

(*  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;