In: Computer Science
Answer the following: a) What is a critical region? b) How can counting semaphores be used to provide exclusive access to a critical region? c) Describe the operation (clearly, in English) of the semWait and semSignal actions of a counting semaphore.
a) critical region - - critical region is also called as rejection region. It rejects the null hypothesis. It is a part of a program where the shared resources are accessed by different methods. Variables are accessed and multiple processes take place in critical region. In a critical region, when a process tries to execute the region statement, the boolean expression b is evaluated. If b is true, statement s is executed. If it is false the process is delayed until b becomes true and no other process is in the region associated with v.
b) semaphore - semaphore is an integer variable which can only be accessed through down and up. It is operating system resources implemented at kernel level. Semaphore operations are atomic. These are of two types
1. wait
2 signal
It takes only integer value.semaphores can also be used to solve various synchronization problems.
Types of semaphore
Counting semaphore (-infinity and+infinity) - it is used for giving control access to resources consisting of finite number Of instances.
Positive value indicates total no. Of successful down operations.
Negative value indicates no. Of processes blocked in blocking queue.
Binary semaphore(0,1)-- it deals with critical section problem. It provides mutual exclusion. It can range over between 0 and 1.
Counting semaphore - -
Struct csemaphore
{
Int value;
Queque L;
} ;
Down (shut csemaphore s)
{
S value = s value - 1;
If ( s value<0)
{
Put this process in S.L() &
Block it
}
}
Up (struct csemaphore s)
{
S.Value=s. Value+1;
If (s.Value <=0)
{
Wake up one of the blocked process
}
}
C) sem wait and sem signal operations:
in the sem _wait () we wait for the signal from another process. what we do is we will decrement the semphore variable value.
Wait(s)
{
While S<=0
// no-operation
S--;
}
Sem signal- in the sem signal, we increment the semaphore value. Only one process can modify the same semaphore value at a time.
Signal (s)
{
S++;
}