コード例 #1
0
        // blocking
        public ItemOfInterest GetItem(ProblemType problemType)
        {
            bool lockTaken = false;

            Monitor.Enter(_blackboard, ref lockTaken);

            ItemOfInterest item = null;

            try
            {
                item = _blackboard.Items.FirstOrDefault(it => it.ProblemType == problemType && it.State != ItemState.Processing);
                if (item != null)
                {
                    item.State = ItemState.Processing;
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(_blackboard);
                }
            }

            return(item);
        }
コード例 #2
0
        public void Process(ItemOfInterest item)
        {
            if (item.ProblemType == ProblemType.Philosophical)
            {
                item.ProblemType = ProblemType.Solved;
            }

            item.State = ItemState.Processed;

            Console.WriteLine("Philosopher processed item " + item.Name);
        }
コード例 #3
0
        public void Process(ItemOfInterest item)
        {
            if (item.ProblemType == ProblemType.Scientific)
            {
                item.ProblemType = ProblemType.Economical;
            }

            item.State = ItemState.Processed;

            Console.WriteLine("Scientist processed item " + item.Name);
        }