| author | haftmann | 
| Tue, 11 Jan 2011 14:12:37 +0100 | |
| changeset 41505 | 6d19301074cf | 
| 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  |