Skip to content
Snippets Groups Projects
Commit ddbbce2b authored by niklasBr's avatar niklasBr
Browse files

Created extra methods functions that where inside main

parent 342e8061
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,21 @@ namespace ConsoleApplication1 ...@@ -16,6 +16,21 @@ namespace ConsoleApplication1
public static void Main(string[] args) public static void Main(string[] args)
{ {
int[] a = getArgsAsIntArr(args);
Buffer buffer = new Buffer();
createNConsumers(a[0], buffer);
createNProducers(a[1], buffer);
}
public static int[] getArgsAsIntArr(string[] args)
{
int nrProd = 0; int nrProd = 0;
int nrCons = 0; int nrCons = 0;
...@@ -33,13 +48,13 @@ namespace ConsoleApplication1 ...@@ -33,13 +48,13 @@ namespace ConsoleApplication1
Debug.Assert(nrProd > -1 && nrCons > -1); Debug.Assert(nrProd > -1 && nrCons > -1);
return new [] { nrProd, nrCons };
}
public static void createNConsumers(int n, Buffer buffer)
{
Buffer buffer = new Buffer();
//Create n new producers where n = received argument //Create n new producers where n = received argument
for(int i = 0; i < nrProd; i++) for (int i = 0; i < n; i++)
{ {
//create new Producer object //create new Producer object
Producer p = new Producer(buffer); Producer p = new Producer(buffer);
...@@ -48,9 +63,12 @@ namespace ConsoleApplication1 ...@@ -48,9 +63,12 @@ namespace ConsoleApplication1
Thread newThread = new Thread(p.Produce); Thread newThread = new Thread(p.Produce);
newThread.Start(); newThread.Start();
} }
}
public static void createNProducers(int n, Buffer buffer)
{
//Create n new consumers where n = received argument //Create n new consumers where n = received argument
for (int i = 0; i < nrCons; i++) for (int i = 0; i < n; i++)
{ {
//create new Consumer object //create new Consumer object
Consumer c = new Consumer(buffer); Consumer c = new Consumer(buffer);
...@@ -61,13 +79,6 @@ namespace ConsoleApplication1 ...@@ -61,13 +79,6 @@ namespace ConsoleApplication1
} }
} }
/*
static void setAsleep()
{
Thread.Sleep(8000);
Consumer.wakeUp();
}
*/
} }
} }
... ...
......
...@@ -18,7 +18,6 @@ namespace ConsoleApplication1.Test ...@@ -18,7 +18,6 @@ namespace ConsoleApplication1.Test
[TestCase] [TestCase]
public void PushSuccessful() public void PushSuccessful()
{ {
Buffer buffer = new Buffer();
for (int i = 0; i < 10 ; i++) for (int i = 0; i < 10 ; i++)
{ {
buffer.Push(_car); buffer.Push(_car);
... ...
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment