餐饮哲学家(分叉订购) [英] Dining philosophers (forks order)

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

问题描述

在监控器"的帮助下,我让哲学家一次吃了2把叉子,怎么让那个哲学家先吃了一把叉子,然后又等了一把?

With the help of "Monitor" I made philosopher take 2 forks at one time to eat,how can I make that philosopher takes one fork and then waits for another one?

推荐答案

一个纯形式的经典问题看起来像这样:每种形式都是一个线程,该线程从代表哲学家的线程中循环通信任务.该通信原语可以是EventWaitHandler或…一个套接字.循环的第一步等待"PickUp",第二步等待"PutDown".

简化的作弊"变体具有受常规锁保护的共享资源的形式.哲学家只是简单地得到左锁,然后得到右叉锁,然后睡了一个花哨,然后以相同的顺序释放了锁.在每个特定的时间点上,当每个哲学家拿到一把叉子并永远等待另一把叉子时,它将创建一个著名的圆形"死锁.

您是否还应证明此僵局或其解决方案.通常,需要同时制作两个版本.

不幸的是,这项任务可能会占用我大约一个小时的时间,而这是我无法承受的.而且您应该独立解决问题.学习练习非常好!

祝你好运,
—SA
A classical problem in its pure form looks like this: each form is a thread looping a communication tasks from a thread representing a philosopher. This communication primitive can be EventWaitHandler or… a socket. First step in the loop waits for "PickUp", a second one for "PutDown".

A simplified "cheating" variant is of a form is a shared resource protected by the regular lock. A philosopher simply gets the lock of left form then the lock of right fork, than sleeps for a wile then releases the locks in the same order. With certain timing it will create a famous "circular" deadlock when each philosopher gets one fork and waits for another one forever.

Are you supposed to demonstrate this deadlock or its resolution as well. Normally, it is required to make both versions.

Unfortunately, the task could absorb some hour of my time or so, which I cannot afford; and you''re supposed to solve the problem independently. It''s very good for your learning to do this exercise!

Good luck,
—SA


请参见
http://rosettacode.org/wiki/Dining_philosophers#C.23 [
See
http://rosettacode.org/wiki/Dining_philosophers#C.23[^]


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

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