src/Pure/Concurrent/counter.scala
author bulwahn
Thu, 07 Jul 2011 23:33:14 +0200
changeset 43704 47b0be18ccbe
parent 43660 bfc0bb115fa1
child 45243 27466646a7a3
permissions -rw-r--r--
floor and ceiling definitions are not code equations -- this enables trivial evaluation of floor and ceiling

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