哲学家就餐C# [英] Dining philosophers c#

查看:167
本文介绍了哲学家就餐C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  线程暂停和恢复C#

我怎样才能暂停5个线程,而且要记住它们的状态。 使它们中的一个吃 另一种是思想,等等。

How can i pause 5 threads ,and to remember their status. cause one of them is eating another is thinking, etc.

推荐答案

这听起来像功课,所以也许你应该看看 http://en.wikipedia.org/wiki/Dining_philosophers_problem

This sounds like homework, so maybe you should check out http://en.wikipedia.org/wiki/Dining_philosophers_problem

简短的回答是,你需要使用.NET的线程系统正常访问有限的资源。锁(),又名Monitor.Enter,是从访问资源停止所有但一个线程的方式之一。再就是信号量和ReaderWriterLocks,等适应任何工具,最适合您的需要。

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.

这篇关于哲学家就餐C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆