-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile1.cs
41 lines (38 loc) · 801 Bytes
/
File1.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
namespace Calculator
{
class Message
{
readonly Object countLock = new Object();
readonly Object textLock = new Object();
int count;
string text;
public void Print()
{
lock (countLock)
{
lock (textLock)
{
while (text == null)
System.Threading.Monitor.Wait(textLock);
System.Console.Out.WriteLine(text + "=" + count);
}
}
}
public string Text
{
set
{
lock (countLock)
{
lock (textLock)
{
++count;
text = value;
System.Threading.Monitor.Pulse(textLock);
}
}
}
}
}
}