author | wenzelm |
Mon, 28 Nov 2011 22:18:19 +0100 | |
changeset 45667 | 546d78f0d81f |
parent 45243 | 27466646a7a3 |
child 45673 | cd41e3903fbf |
permissions | -rw-r--r-- |
43660 | 1 |
/* Title: Pure/Concurrent/counter.scala |
45667
546d78f0d81f
explicit indication of modules for independent Scala library;
wenzelm
parents:
45243
diff
changeset
|
2 |
Module: Library |
43660 | 3 |
Author: Makarius |
4 |
||
5 |
Synchronized counter for unique identifiers < 0. |
|
6 |
||
7 |
NB: ML ticks forwards, JVM ticks backwards. |
|
8 |
*/ |
|
9 |
||
10 |
package isabelle |
|
11 |
||
12 |
||
13 |
object Counter |
|
14 |
{ |
|
15 |
type ID = Long |
|
45243 | 16 |
def apply(): Counter = new Counter |
43660 | 17 |
} |
18 |
||
45243 | 19 |
class Counter private |
43660 | 20 |
{ |
21 |
private var count: Counter.ID = 0 |
|
22 |
||
23 |
def apply(): Counter.ID = synchronized { |
|
24 |
require(count > java.lang.Long.MIN_VALUE) |
|
25 |
count -= 1 |
|
26 |
count |
|
27 |
} |
|
28 |
} |
|
29 |