src/Pure/Concurrent/counter.scala
author wenzelm
Sat, 20 Aug 2011 23:35:30 +0200
changeset 44338 700008399ee5
parent 43660 bfc0bb115fa1
child 45243 27466646a7a3
permissions -rw-r--r--
refined Graph implementation: more abstract/scalable Graph.Keys instead of plain lists -- order of adjacency is now standardized wrt. Key.ord;

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

Synchronized counter for unique identifiers < 0.

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

package isabelle


object Counter
{
  type ID = Long
}

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

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