Dining philosophers c# [duplicate]
Possible Duplicate:
Threads pausing and resuming c#
How can i pause 5 threads ,and to remember their status. cause one of them is eating another is thinking, etc.
This sounds like homework, so maybe you should check out http://en.wikipedia.org/wiki/Dining_philosophers_problem
The short answer is you need to use .NET's threading system to properly access the limited resources. lock(), aka Monitor.Enter, is one way of stopping all but one thread from accessing a resource. Then there are semaphores, and ReaderWriterLocks, etc. Adapt whichever tool fits best for your need.
What you could do is have them write to a concurrent stream/ file each time they change with a timestamp and then analyse that. (good place to use RX :-)
The thing is that you want to see the whole process, a snapshot every so often would not necessarily show the whole picture.
If you really want to pause you could have them check some shared (static) flag, and them have them wait (spin, sleep) there.
GJ
精彩评论