static void Main(string[] args) { RemoteServerGroup.Initiate(args); // Inicjalizacja singletona Remote Server Group // Tutaj powinny zostać stworzone wszystkie Monitory i zmienne warunkowe BufforMonitor sharedBufforMonitor = new BufforMonitor(3, RemoteServerGroup.Instance.NodeAddressNumber); ConditionalVariable empty = new ConditionalVariable("Empty", sharedBufforMonitor); ConditionalVariable full = new ConditionalVariable("full", sharedBufforMonitor); RemoteServerGroup.StartRemoteExecution(); // Barriera zapewniająca, że wszystkie servery wykonają poprawnie całą inicjalizację obiektów if (RemoteServerGroup.Instance.NodeAddressNumber < 2) { Consumer consumer = new Consumer(empty, full, sharedBufforMonitor); consumer.Consume(); } else { Producer producer = new Producer(empty, full, sharedBufforMonitor); producer.Produce(); } RemoteServerGroup.Finish(); }
/// <summary> /// Performs the specified number of consumption iterations. /// A consumption iteration consists of: /// 1) Consume an object (by calling Consume) /// 2) Call Report, so the change can be reported. /// 3) Wait for a number of milli-seconds (between 0 and maxDelay) /// </summary> private async Task ConsumeWithRandomDelay(int iterations, int maxDelay) { Random rng = new Random(); for (int i = 0; i < iterations; i++) { _consumer.Consume(); _reporter.Report(); await Task.Delay(rng.Next(maxDelay)); } }