| author | huffman |
| Tue, 23 Aug 2011 14:11:02 -0700 | |
| changeset 44457 | d366fa5551ef |
| parent 43719 | ba1b2c918c32 |
| child 45248 | 3b7b64b194ee |
| permissions | -rw-r--r-- |
| 38840 | 1 |
/* Title: Pure/Concurrent/volatile.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Volatile variables. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
class Volatile[A](init: A) |
|
11 |
{
|
|
12 |
@volatile private var state: A = init |
|
| 43719 | 13 |
def apply(): A = state |
| 38840 | 14 |
def change(f: A => A) { state = f(state) }
|
15 |
def change_yield[B](f: A => (B, A)): B = |
|
16 |
{
|
|
17 |
val (result, new_state) = f(state) |
|
18 |
state = new_state |
|
19 |
result |
|
20 |
} |
|
21 |
} |
|
22 |