diff --git a/Aufgabe3/ConsoleApplication1/Buffer.cs b/Aufgabe3/ConsoleApplication1/Buffer.cs index 816b685867f4c557f4efc472a3d624aede3567c3..0a9d5f5a819261f1ebdacd8b1556d83a65dfcaf7 100644 --- a/Aufgabe3/ConsoleApplication1/Buffer.cs +++ b/Aufgabe3/ConsoleApplication1/Buffer.cs @@ -23,7 +23,7 @@ namespace ConsoleApplication1 throw new Exception("Buffer full"); } - + carQueue.Enqueue(c); } diff --git a/Aufgabe3/ConsoleApplication1/Consumer.cs b/Aufgabe3/ConsoleApplication1/Consumer.cs index 4b10acddf2194927523318b1d756db145416de59..55248acbe1fc2261b16b7358d7644895857c154a 100644 --- a/Aufgabe3/ConsoleApplication1/Consumer.cs +++ b/Aufgabe3/ConsoleApplication1/Consumer.cs @@ -21,18 +21,20 @@ namespace ConsoleApplication1 { while (true) { + //if isAsleep = true: method checks if wakeConsumersUp has been set to true every 50ms if (isAsleep) { Console.WriteLine("consumer asleep..."); Thread.Sleep(50); - + //if wakeConsumersUp = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next interation if (wakeConsumersUp) { Console.WriteLine("consumer was woken up"); isAsleep = false; } } + //if consumer isnt asleep: consumer gets mutex from buffer, wakes up producers if buffer is full and removes cars if consumer is not empty else { Thread.Sleep(r.Next(500, 1500)); @@ -49,6 +51,8 @@ namespace ConsoleApplication1 Car c = b.pop(); Console.WriteLine("car pulled out of parking space. car id = " + c.getThisCarId()); } + + //if buffer is empty: consumers are set to sleep, own instance is set to sleep else { wakeConsumersUp = false; @@ -60,6 +64,8 @@ namespace ConsoleApplication1 } } } + + //this consumer instance can be woken up by calling this method public static void wakeUp() { wakeConsumersUp = true;