public static void Main() { var bus = new SharedBus(1000); var threads = new Thread[100]; for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread(() => { ExecuteComm(bus); }); threads[i].Start(); } // wait for all threads to complete foreach (var thread in threads) { thread.Join(); } Debug.WriteLine($"Account's balance is {bus.GetOperationValue()}"); // Output should be: // Account's balance is 2000 Thread.Sleep(Timeout.Infinite); }
static void ExecuteComm(SharedBus bus) { float[] operations = { 0, 2, -3, 6, -2, -1, 8, -5, 11, -6 }; foreach (var ops in operations) { if (ops >= 0) { bus.Transmit(ops); } else { bus.Receive(Math.Abs(ops)); } } }