ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > CLASS (2016-2017-1)-62903-06102-1 > 2014329600164童逸琦 >
理发师问题 Version 0
👤 Author: by 371516709qqcom 2017-01-08 11:13:55
Define n=5;
Semaphore mutex=1;
Semaphore customers=0;
Semaphore barbers=1;
Int waiting=0; //等候理发的顾客数


Void baber()
{
While(true
{
Wait(customers));//若无顾客,理发师睡眠
Wait(mutex);
Waiting- -;
Signal(mutex);
Signal(barbar);
}

Void customer()
{
wait(mutex);
If(waiting<n)
{
Waiting++;
Signal(mutex);
Signal(customers);//如果理发师睡觉,叫醒理发师
Wait(barber);//理发师在理发,顾客等候;
}
Else
Signal(mutex);//

Please login to reply. Login

Reversion History

Loading...
No reversions found.