src/Pure/Concurrent/counter.scala
author haftmann
Mon, 26 Dec 2011 22:17:10 +0100
changeset 45989 b39256df5f8a
parent 45673 cd41e3903fbf
child 46712 8650d9a95736
permissions -rw-r--r--
moved theorem requiring multisets from More_List to Multiset

/*  Title:      Pure/Concurrent/counter.scala
    Module:     PIDE
    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
  }
}