Beispiel #1
0
        private static void InitializeAlchemists(IAlchemistsQueue queue)
        {
            var random         = new Random();
            var alchemistTypes = Enum.GetValues(typeof(AlchemistType));

            for (int i = 0; i < Configuration.NumberOfAlchemists; i++)
            {
                var type      = (AlchemistType)alchemistTypes.GetValue(random.Next(alchemistTypes.Length));
                var alchemist = new Alchemist(type, queue);
                new Thread(() => alchemist.Run()).Start();
            }
        }
Beispiel #2
0
        static void RunAlchemists()
        {
            while (true)
            {
                int alchemistType = random.Next(0, 4);
                var alchemist     = new Alchemist(nextAlchemistId, (AlchemistType)alchemistType);
                alchemists.Add(alchemist);

                new Thread(() => alchemist.WaitForResources(distributor.SemAlchemists[(int)alchemist.Type]));   //wait for appropriate resources

                distributor.SemAlchemistCount.WaitOne();
                distributor.AlchemistCount[(int)alchemist.Type]++;
                distributor.SemAlchemistCount.Release();

                Thread.Sleep(random.Next(5, 31) * 1000);
            }
        }