| author | blanchet |
| Wed, 04 May 2011 19:35:48 +0200 | |
| changeset 42680 | b6c27cf04fe9 |
| parent 38840 | ec75dc58688b |
| child 43719 | ba1b2c918c32 |
| 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 |
|
13 |
def peek(): A = state |
|
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 |