diff --git a/ADIS_Csharp/ConsoleApp/Program.cs b/ADIS_Csharp/ConsoleApp/Program.cs index 942b3a2..0f3c322 100644 --- a/ADIS_Csharp/ConsoleApp/Program.cs +++ b/ADIS_Csharp/ConsoleApp/Program.cs @@ -132,7 +132,7 @@ class ThreadStop2 #endif -#if true +#if false class SimpleBlocking { @@ -167,4 +167,38 @@ 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 \ No newline at end of file