ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU-(2020-2021)-1 > student homework > 2018329621176_曹欣然 >
2018329621176_曹欣然_hw06 Version 0
👤 Author: by 439731491qqcom 2021-01-05 07:08:36

  • Describe semaphore and its operations.


A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal(). The wait() operation was originally termed P; signal() was originally called V. The definition of wait() is as follows:




wait(s){
while S<=0;//no-op
S--;
}



The definition of signal() is as follows:




signal(S){
S++
}



All the modificaitons to the integer value of the semaphore in the wait() and signal() operations must be excuted indivisibly. That is, when one process modifies the semaphore value, no other process can simultaneously modify that same semaphore value. In addition, in the case of wait(S), the testing integer value of S(S<=0), and its possible modification(S--), must be executed without interruption.




  • Own case related with process synchronizatioin:


The museum can accommodate up to 500 people and has an entrance, which allows only one person to pass through at a time. The visitors’ activities are described as follows:




Visitor's progress:
{
...
Enter;
...
Visit;
...
Out;
}



The solution of solving the mutex and synchronization in this progress is as follows:




semaphore empty = 500;
semaphore mutex = 1;
do
{
wait(empty);
wait(mutex);
Enter;
signal(mutex);
Visit;
waiit(mutex);
Out;
signal(mutex);
signal(empty);
}


Please login to reply. Login

Reversion History

Loading...
No reversions found.