Skip to content
Snippets Groups Projects
Commit fdaafc9e authored by Niklas Bretz's avatar Niklas Bretz
Browse files

Commented code

parent 0113a6f8
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ namespace ConsoleApplication1
throw new Exception("Buffer full");
}
carQueue.Enqueue(c);
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment