Advanced Distributed Systems module at HSLU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
945 B

using System;
using System.Threading;
namespace Sync_Ueb01_Counter
{
class CounterTest
{
private String id;
private Counter counter;
private object locker = new object();
public CounterTest(String id, Counter counter)
{
this.id = id;
this.counter = counter;
}
void Go()
{
while (true)
{
Thread.Sleep(100);
Console.WriteLine(id + counter.NextNumber());
}
}
static void Main()
{
Counter counter = new Counter();
CounterTest ct1 = new CounterTest("T1: ", counter);
CounterTest ct2 = new CounterTest("T2: ", counter);
CounterTest ct3 = new CounterTest("T3: ", counter);
new Thread(ct1.Go).Start();
new Thread(ct2.Go).Start();
new Thread(ct3.Go).Start();
}
}
}