以文本方式查看主题 - 计算机科学论坛 (http://bbs.xml.org.cn/index.asp) -- 『 计算机考研交流 』 (http://bbs.xml.org.cn/list.asp?boardid=67) ---- 银行业务PV题 (http://bbs.xml.org.cn/dispbbs.asp?boardid=67&rootid=&id=39853) |
-- 作者:mxf3306 -- 发布时间:11/9/2006 6:02:00 PM -- 银行业务PV题 semaphore number[n] //初值为1 int next =0; semaphore customer =0; semaphore teller = n; semaphore mutex = 1; teller() customer() v(customer); v(number[next]); 仓促之中 |
-- 作者:Supremgoooo -- 发布时间:11/14/2006 9:23:00 AM -- semaphore number[n] //初值为1 我认为不能限制人数 |
-- 作者:mxf3306 -- 发布时间:11/15/2006 4:03:00 PM -- 把n尽量设大就是了。一切从实际出发,实际上是不可能达到无限个进程的。 |
-- 作者:DavidPotter -- 发布时间:11/18/2006 1:15:00 PM -- 为什么不根据teller的人数来计算呢?我认为每个teller是一个进程。 这样customer可以先扫描teller的状态然后再去办理业务。 |
-- 作者:mxf3306 -- 发布时间:11/19/2006 2:34:00 PM --
扫描是什么意思?是不是就是忙等待?把你的解答贴出来看一下吧。 |
-- 作者:DavidPotter -- 发布时间:11/20/2006 7:12:00 PM -- //semaphore teller[n];//初始化都为1 semaphore queue;//0 所有的customer都在此拿号排队。 semaphore customer;//0 顾客数 semaphore mutex//1 int avail_teller[n];//指示去哪一个窗口。 for (int i=0;i<n; i++) teller(int i) customer() |
-- 作者:mxf3306 -- 发布时间:11/21/2006 8:17:00 PM -- 我觉得这样做是不行的,完全没体现出取号的过程,也没体现出号小的先进行服务的限制。而这正是这个题目考查的关键。你的解法其实本质上就是对于customer对于teller资源的共享。那还不如就直接让 queue初值等于n,所有customer都P(queue)呢。 |
-- 作者:christmasliu -- 发布时间:12/3/2006 4:34:00 PM -- semaphore number[m] //初值为0 semaphore customer =1; semaphore c_mutex = 1;//用于顾客取号 semaphore t_mutex = 1;//用于柜员叫顾客 teller() 我写的,各位大侠看一下哈! |
-- 作者:runningwulf -- 发布时间:12/3/2006 7:39:00 PM -- 为什么要设number[m],代表什么值?是代表顾客排队到第m号柜员上吗? 我认为不应该在顾客等待的时候就将其分配到柜员上吧。 |
-- 作者:christmasliu -- 发布时间:12/4/2006 11:11:00 AM -- 不是,m是一个很大的数,和那个n没关系。 number[m]是一个对应每个顾客号码的信号量。每个顾客等待在自己的号码上,等一个柜员把他唤醒。 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
109.375ms |