src/Pure/Concurrent/volatile.scala
author wenzelm
Fri, 18 Nov 2011 22:32:57 +0100
changeset 45582 78f59aaa30ff
parent 45248 3b7b64b194ee
child 45667 546d78f0d81f
permissions -rw-r--r--
sequential lemmas to accomodate static rule attributes;

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

Volatile variables.
*/

package isabelle


object Volatile
{
  def apply[A](init: A): Volatile[A] = new Volatile(init)
}


class Volatile[A] private(init: A)
{
  @volatile private var state: A = init
  def apply(): 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
  }
}