src/Pure/Concurrent/volatile.scala
author wenzelm
Wed, 04 Jan 2012 15:41:18 +0100
changeset 46117 edd50ec8d471
parent 45673 cd41e3903fbf
child 46687 7e47ae85e161
permissions -rw-r--r--
updated version information; discontinued somewhat obsolete hotspot check: OpenJDK 1.7 works reasonably well, and final bundling provides certain tested JDK/JRE versions;

/*  Title:      Pure/Concurrent/volatile.scala
    Module:     PIDE
    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
  }
}