summaryrefslogtreecommitdiff
path: root/sources/scala/concurrent/SyncVar.scala
blob: a05ef32f86b250b864c2b80608f7b23d10220150 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package scala.concurrent;

class SyncVar[a] {
  private var isDefined: Boolean = false;
  private var value: a = _;
  def get = synchronized {
    if (!isDefined) wait();
    value
  }
  def set(x: a) = synchronized {
    value = x ; isDefined = true ; notifyAll();
  }
  def isSet: Boolean =
    isDefined;
  def unset = synchronized {
    isDefined = false;
  }
}