Example #1
0
        static void Main()
        {
            AutoResetEvent autoRest = new AutoResetEvent(false);

            string[]   instructions = File.ReadAllLines("Day18\\Input\\input.txt");
            AOCProgram program0     = new AOCProgram(0, instructions, autoRest);
            AOCProgram program1     = new AOCProgram(1, instructions, autoRest);

            program0.SetPartner(program1);
            program1.SetPartner(program0);

            program0.StartAOCProgram();
            program1.StartAOCProgram();

            while (true)
            {
                if (program0.thread.ThreadState == ThreadState.WaitSleepJoin &&
                    program1.thread.ThreadState == ThreadState.WaitSleepJoin)
                {
                    Console.WriteLine("Both program done/deadlocked... exit");
                    break;
                }
                else
                {
                    Console.WriteLine("MasterThread: Check threads again in 5s");
                    Thread.Sleep(5000);
                }
            }
            Console.WriteLine("Program1, sendcount: " + program1.sendCount);
            Console.WriteLine("Program0, sendcount: " + program0.sendCount);
            Console.WriteLine();
        }
Example #2
0
 public void SetPartner(AOCProgram program)
 {
     this.partner = program;
 }