src/Pure/Concurrent/counter.scala
author wenzelm
Mon, 28 Nov 2011 22:18:19 +0100
changeset 45667 546d78f0d81f
parent 45243 27466646a7a3
child 45673 cd41e3903fbf
permissions -rw-r--r--
explicit indication of modules for independent Scala library;

/*  Title:      Pure/Concurrent/counter.scala
    Module:     Library
    Author:     Makarius

Synchronized counter for unique identifiers < 0.

NB: ML ticks forwards, JVM ticks backwards.
*/

package isabelle


object Counter
{
  type ID = Long
  def apply(): Counter = new Counter
}

class Counter private
{
  private var count: Counter.ID = 0

  def apply(): Counter.ID = synchronized {
    require(count > java.lang.Long.MIN_VALUE)
    count -= 1
    count
  }
}