blob: 7184ff7c6143a97963c221379e1f8d1ceac03b1b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package scala.concurrent;
class SyncChannel[a]() extends Monitor() {
private var data: a = _;
private var reading = false;
private var writing = false;
def write(x: a) = synchronized {
await(!writing);
data = x;
writing = true;
if (reading) notifyAll();
else await(reading)
}
def read: a = synchronized {
await(!reading);
reading = true;
await(writing);
val x = data;
writing = false;
reading = false;
notifyAll();
x
}
}
|