src/Pure/Concurrent/counter.scala
author wenzelm
Sat, 22 Oct 2011 19:00:03 +0200
changeset 45243 27466646a7a3
parent 43660 bfc0bb115fa1
child 45667 546d78f0d81f
permissions -rw-r--r--
class Counter as abstract datatype;

/*  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
  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
  }
}