Re: [理工] 104 台大资工 线代 OS DS 对答案

楼主: ken52011219 (呱)   2016-09-21 19:21:41
※ 引述《tzutengweng (神奇的汤姆)》之铭言:
我先附题目
Consider a process synchrinization problem , in which we have 5 people
competing for 4 chairs , and each chair can be used by one person at a time
Let the competing go by rounds. That is , 5 people compete for 4 chairs in the
begining of each round , and the 4 winners release their chairs at the end of
each round so that the next round starts .
Please use semaphores to write programs for the entry and exit section of
the 5 people so that every person will win at least ine time in competing
the chairs for every 3 consecutive rounds.
: : 【OS】
: : 8.好像表达的没有很好 想参考一下大家怎么写的QQ
: : Chair: semaphone=4;
: : Pi: int=0;
: : while(前两轮)
: : {
: : Pi++;
: : wait(chair);
: : C.S.
: : signal(chair);
: : }
: : if(Pi==0)then wait(chair);
: : wait(chair);
: : C.S.
: : signal(chair);
:
楼主: ken52011219 (呱)   2016-09-22 10:36:00
我的code 满足同步标准的 1.mutex 2. Progress 但3可能会不满足但要满足3.bound waiting 的条件我认为需要知道五个人怎么竞争的 才能更详细地写出 否则我就先以process本身得到进入许可速度为基准 反正才五个process XDD

Links booklink

Contact Us: admin [ a t ] ucptt.com