src/Pure/Concurrent/volatile.scala
author wenzelm
Wed, 02 Feb 2011 13:38:09 +0100
changeset 41681 b5d7b15166bf
parent 38840 ec75dc58688b
child 43719 ba1b2c918c32
permissions -rw-r--r--
Future.join_results: discontinued post-hoc recording of dynamic dependencies; abstract Task_Queue.deps; tuned signature; tuned;

/*  Title:      Pure/Concurrent/volatile.scala
    Author:     Makarius

Volatile variables.
*/

package isabelle


class Volatile[A](init: A)
{
  @volatile private var state: A = init
  def peek(): A = state
  def change(f: A => A) { state = f(state) }
  def change_yield[B](f: A => (B, A)): B =
  {
    val (result, new_state) = f(state)
    state = new_state
    result
  }
}