ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU-(2020-2021)-1 > student homework > 2018329621049_胡成一 >
homework6_胡成一_2018329621049 Version 0
👤 Author: by 450766287qqcom 2020-12-08 06:02:44
Semaphore is simply a variable that is non-negative and shared between threads. A semaphore is a signaling mechanism, and a thread that is waiting on a semaphore can be signaled by another thread. It uses two atomic operations, 1)wait, and 2) signal for the process synchronization.



int S = 1;
int Sa = 0;//apple
int So = 0;//orange
main()
{
cobegin
father();
son();
daughter();
coend()
}
father()
{
while(true)
{
P(S);
if(it is an orange) V(So);
else V(Sa);
}
}
son()
{
while(true)
{
P(So);
V(S);
}
}
daughter()
{
while(true)
{
P(sa);
V(S);
}
}

Please login to reply. Login

Reversion History

Loading...
No reversions found.