/* Main function */ public static void Main() { /* Create object */ CombinationaloLogic cLogic = new CombinationaloLogic(4); /* Read the specified file */ cLogic.readFile(); //cL.print(); //int start = 0; //int end = 15; //cL.CountNumber_of_Ones(0); /* Create the workers */ Thread worker1 = new Thread(new ThreadStart( () => cLogic.CountNumber_of_Ones(0) )); worker1.Name = "worker1"; /* Create the workers */ Thread worker2 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(1))); worker2.Name = "worker2"; /* Create the workers */ Thread worker3 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(2))); worker3.Name = "worker3"; /* Create the workers */ Thread worker4 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(3))); worker4.Name = "worker4"; /* Count the time that has elapsed */ Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); /* Threads start their work */ worker1.Start(); worker2.Start(); worker3.Start(); worker4.Start(); /* Threads have finished their work */ worker1.Join(); worker2.Join(); worker3.Join(); worker4.Join(); /* Stop the clock */ stopWatch.Stop(); /* Get the elapsed time as a TimeSpan value. */ TimeSpan ts = stopWatch.Elapsed; Console.WriteLine(); Console.WriteLine("Elapsed time:"); /* Format and display the TimeSpan value. */ string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(elapsedTime, "RunTime"); Console.WriteLine("Final number of ones after computation is " + cLogic.NUM_OF_ONES); }
/* Main function */ public static void Main() { /* Create object */ CombinationaloLogic cLogic = new CombinationaloLogic(4); /* Read the specified file */ cLogic.readFile(); //cL.print(); //int start = 0; //int end = 15; //cL.CountNumber_of_Ones(0); /* Create the workers */ Thread worker1 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(0))); worker1.Name = "worker1"; /* Create the workers */ Thread worker2 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(1))); worker2.Name = "worker2"; /* Create the workers */ Thread worker3 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(2))); worker3.Name = "worker3"; /* Create the workers */ Thread worker4 = new Thread(new ThreadStart(() => cLogic.CountNumber_of_Ones(3))); worker4.Name = "worker4"; /* Count the time that has elapsed */ Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); /* Threads start their work */ worker1.Start(); worker2.Start(); worker3.Start(); worker4.Start(); /* Threads have finished their work */ worker1.Join(); worker2.Join(); worker3.Join(); worker4.Join(); /* Stop the clock */ stopWatch.Stop(); /* Get the elapsed time as a TimeSpan value. */ TimeSpan ts = stopWatch.Elapsed; Console.WriteLine(); Console.WriteLine("Elapsed time:"); /* Format and display the TimeSpan value. */ string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(elapsedTime, "RunTime"); Console.WriteLine("Final number of ones after computation is " + cLogic.NUM_OF_ONES); }