diff --git a/Aufgabe3/ConsoleApplication1/Consumer.cs b/Aufgabe3/ConsoleApplication1/Consumer.cs index 24a347aa7648b999cd01b0fd82850a15b84928b9..334c90ef4af0c323c90f98dbb787486d9535e8f4 100644 --- a/Aufgabe3/ConsoleApplication1/Consumer.cs +++ b/Aufgabe3/ConsoleApplication1/Consumer.cs @@ -27,7 +27,7 @@ namespace ConsoleApplication1 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 = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next iteration if (_wakeConsumersUp) { Console.WriteLine("consumer was woken up"); diff --git a/Aufgabe3/ConsoleApplication1/Producer.cs b/Aufgabe3/ConsoleApplication1/Producer.cs index 94b2d371081e7991909d8d8cacea99c881aae612..e2a54b4e05ce638c60d2671bf86f04f4e1cf8721 100644 --- a/Aufgabe3/ConsoleApplication1/Producer.cs +++ b/Aufgabe3/ConsoleApplication1/Producer.cs @@ -16,7 +16,7 @@ namespace ConsoleApplication1 public Producer(Buffer buffer) { _random = new Random(); - this._buffer = buffer; + _buffer = buffer; } @@ -24,17 +24,20 @@ namespace ConsoleApplication1 { while (true) { + //if isAsleep = true: method checks if wakeProducersUp has been set to true every 50ms if (_isAsleep) { Console.WriteLine("producer asleep..."); Thread.Sleep(50); + //if wakeProducersUp = true is asAsleep is set to true and if(isAsleep) "loop" is exited on next iteration if (_wakeProducersUp) { Console.WriteLine("producer was woken up"); _isAsleep = false; } } + //if producer isnt asleep: producer gets mutex from buffer, wakes up consumers if buffer is empty and removes cars if producers is not full else { Thread.Sleep(_random.Next(500, 1500)); @@ -52,6 +55,7 @@ namespace ConsoleApplication1 _buffer.push(c); Console.WriteLine("car " + c.getThisCarId() + " added"); } + //if buffer is full: producers are set to sleep, own instance is set to sleep else { _wakeProducersUp = false; @@ -65,6 +69,7 @@ namespace ConsoleApplication1 } } + //this consumer instance can be woken up by calling this method public static void WakeUp() { _wakeProducersUp = true;