Recents in Beach

Semaphores

Previous                                                          Next⏩



       For the solution to the critical section problem one synchronization tool is used which is known as semaphores. A semaphore ‘S’ is an integer variable which is accessed through two standard operations such as wait and signal. These operations were originally termed ‘P’ (for wait means to test) and ‘V’ (for single means to increment). The classical definition of wait is

Wait (S)
{
While (S <= 0)
{
Test;
}
S--;
}


the classical definition of the signal is

 Signal (S)
{
S++;
}
In case of wait the test condition is executed with interruption and the decrement is executed without interruption.

Binary Semaphore:

A binary semaphore is a semaphore with an integer value which can range between 0 and 1. Let ‘S’ be a counting semaphore. To implement the binary semaphore we need following the structure of data.
Binary Semaphores S1, S2; int C;
Initially S1 = 1, S2 = 0 and the value of C is set to the initial value of the counting semaphore ‘S’. Then the wait operation of the binary semaphore can be implemented as follows.

Wait (S1
C--;
if (C < 0)
{           Signal (S1); 
             Wait (S2);
     }

The signal operation of the binary semaphore can be implemented as follows: 


Wait (S1);
C++;
if (C <=0)
      Signal (S2); 
Else 
    Signal (S1); 


Counting Semaphore

There are the scenarios in which more than one processes need to execute in critical section simultaneously. However, counting semaphore can be used when we need to have more than one process in the critical section at the same time.
The programming code of semaphore implementation is shown below which includes the structure of semaphore and the logic using which the entry and the exit can be performed in the critical section.


struct Semaphore
{
    int value; 
// processes that can enter in the critical section simultaneously.   
    queue type L; // L contains set of processes which get blocked   
}  
Down (Semaphore S)  
{  
    SS.value = S.value - 1; //semaphore's value will get decreased when a new   
    //process enter in the critical section   

    if (S.value< 0)  
    {  
        put_process(PCB) in L; //if the value is negative then 
        //the process will get into the blocked state.
  
        Sleep();   
    }  
    else  
        return;  
}  
up (Semaphore s)  
{  
    SS.value = S.value+1; //semaphore value will get increased when   
    //it makes an exit from the critical section.   

    if(S.value<=0)  
    {  
        select a process from L; //if the value of semaphore is positive 
        //then wake one of the processes in the blocked queue. 
 
        wake-up();  
    }  
    }  
}  




Previous                                                          Next⏩


  1. What is an Operating System ?
  2. Discuss the structure off OS ?
  3. Explain type of OS?
  4. Explain Function of OS?
  5. Explain OS Services ?
  6. What do mean by system call ?List different type ofsystem call available ?

  1. what is process ? and Characteristics ?
  2. What is different process state? explain the same in details?
  3. write short note on user level and kernal level threads?
  4. explain what is thread and its type ?
  5. explain scheduler ? (short term,medium term,and long term)
  6. state and explain scheduling criteria ?
  7. Explain scheduling algorithm ? [ FCFS,SJF,PRIORITY,ROUND ROBINE.]    

  1. What is process synchronization ? explain critical section problem and race condition ?
  2. what is Race Condition ?
  3. what is critical section problem?
  4. explain classical problem of synchronization?
  5. explain bounded - buffer problem?
  6. explain reader - writer problem ?
  7. explain Dining Philosophers Problem ?
  8. explain semaphores ? its type ?

  1.  What is deadlock ?
  2. What are the 4 condition to produce deadlock ?
  3. explain methods of handling deadlock ?
  4. explain in detail deadlock prevention ?
  5. write short note on deadlock avoidance ?
  6. explain deadlock detection ? 
  7. explain Banker algorithm with example ? 

Post a Comment

0 Comments