// 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); }
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); }
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); }