1/* Title: Pure/Concurrent/counter.scala 2 Author: Makarius 3 4Synchronized counter for unique identifiers < 0. 5 6NB: ML ticks forwards, JVM ticks backwards. 7*/ 8 9package isabelle 10 11 12object Counter 13{ 14 type ID = Long 15 def make(): Counter = new Counter 16} 17 18final class Counter private 19{ 20 private var count: Counter.ID = 0 21 22 def apply(): Counter.ID = synchronized { 23 require(count > java.lang.Long.MIN_VALUE) 24 count -= 1 25 count 26 } 27 28 override def toString: String = count.toString 29} 30