diff --git a/Aufgabe3/ConsoleApplication1/Program.cs b/Aufgabe3/ConsoleApplication1/Program.cs index 079df732dc4514828a29bd693f3e444ae5c40223..23a602d42718bcc0bd765258e2fff0391af72548 100644 --- a/Aufgabe3/ConsoleApplication1/Program.cs +++ b/Aufgabe3/ConsoleApplication1/Program.cs @@ -11,14 +11,29 @@ namespace ConsoleApplication1 public static - class Program + class Program { 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 nrCons = 0; - + //Parse received program arguments to int try { @@ -30,27 +45,30 @@ namespace ConsoleApplication1 Console.WriteLine("Please provide two positive integers as program arguments"); Environment.Exit(1); } - - Debug.Assert(nrProd > -1 && nrCons > -1); - - + Debug.Assert(nrProd > -1 && nrCons > -1); - Buffer buffer = new Buffer(); + return new [] { nrProd, nrCons }; + } + public static void createNConsumers(int n, Buffer buffer) + { //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 Producer p = new Producer(buffer); - + //create new Thread and start it Thread newThread = new Thread(p.Produce); newThread.Start(); } + } + public static void createNProducers(int n, Buffer buffer) + { //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 Consumer c = new Consumer(buffer); @@ -58,16 +76,9 @@ namespace ConsoleApplication1 //create new Thread and start it Thread newThread = new Thread(c.Consume); newThread.Start(); - + } } -/* - static void setAsleep() - { - Thread.Sleep(8000); - Consumer.wakeUp(); - } -*/ } } diff --git a/Aufgabe3/ConsoleApplication1/Test/BufferTest.cs b/Aufgabe3/ConsoleApplication1/Test/BufferTest.cs index 7e7b0ff6db16ede7e2f5d59c96899a14d5848e57..a7b539c5d07bc8b6c53d0a021eaf393b9f7f30e7 100644 --- a/Aufgabe3/ConsoleApplication1/Test/BufferTest.cs +++ b/Aufgabe3/ConsoleApplication1/Test/BufferTest.cs @@ -18,7 +18,6 @@ namespace ConsoleApplication1.Test [TestCase] public void PushSuccessful() { - Buffer buffer = new Buffer(); for (int i = 0; i < 10 ; i++) { buffer.Push(_car); diff --git a/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.exe b/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.exe index 05cf18f1c25c60f1056a8f2c605b87acb549ce5a..db3e14647c69b0a833948cd286a47be05fd65a32 100644 Binary files a/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.exe and b/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.exe differ diff --git a/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.pdb b/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.pdb index 93622a747be154cb3ef7ee031f355b04c7e597eb..fea1f3f998750ba0129fde6ed85f29d8d6119c73 100644 Binary files a/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.pdb and b/Aufgabe3/ConsoleApplication1/bin/Debug/ConsoleApplication1.pdb differ diff --git a/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.exe b/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.exe index 05cf18f1c25c60f1056a8f2c605b87acb549ce5a..db3e14647c69b0a833948cd286a47be05fd65a32 100644 Binary files a/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.exe and b/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.exe differ diff --git a/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.pdb b/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.pdb index 93622a747be154cb3ef7ee031f355b04c7e597eb..fea1f3f998750ba0129fde6ed85f29d8d6119c73 100644 Binary files a/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.pdb and b/Aufgabe3/ConsoleApplication1/obj/Debug/ConsoleApplication1.pdb differ