add 1.2.4 lock construct in CSharp project

main
Jonas Arnold 4 years ago
parent 7c1159ca45
commit 8e441919a9
  1. 36
      ADIS_Csharp/ConsoleApp/Program.cs

@ -132,7 +132,7 @@ class ThreadStop2
#endif
#if true
#if false
class SimpleBlocking
{
@ -168,3 +168,37 @@ class SimpleBlocking
}
#endif
#if true
class LockingConstruct1 {
private static object locker = new object();
static void Main()
{
long sum = 0;
Thread t1 = new Thread(delegate()
{
lock (locker)
{
for (int i = 0; i <= 1000; i++) {
sum += i;
}
}
});
Thread t2 = new Thread(delegate()
{
lock (locker)
{
Console.WriteLine("Summe = " + sum);
}
});
t1.Start();
t2.Start();
}
}
#endif
Loading…
Cancel
Save