コード例 #1
0
        private IEnumerable <Expression> __concurrentmain(CancellationToken __cancellation, Action <object> __success, Action <Exception> __failure)
        {
            var names = new[] { "Kant", "Archimedes", "Nietzche", "Plato", "Spinoza", };
            var meals = 0;

            if (Arguments.Length != 1 || !int.TryParse(Arguments[0], out meals))
            {
                meals = 3;
            }
            //create chopsticks
            var chopsticks = names.Select(n => spawn <chopstick>()).ToArray();
            //create philosophers
            var phCount = names.Length;
            var stopper = new StopCount(phCount);

            for (int i = 0; i < phCount; i++)
            {
                var left  = chopsticks[i];
                var right = i == phCount - 1 ? chopsticks[0] : chopsticks[i + 1];
                spawn <philosopher>(names[i], left, right, meals, stopper);
            }

            {
                __dispatch("main");
                if (__success != null)
                {
                    __success(null);
                }
                yield break;
            }
        }
コード例 #2
0
 public philosopher(string name, chopstick left, chopstick right, int meals, StopCount stop)
 {
     _name  = name;
     _left  = left;
     _right = right;
     _meals = meals;
     _stop  = stop;
 }