A simple introduction to binary semaphore.Types of semaphore.Example and simple implementation using code.
Size: 57.45 KB
Language: en
Added: Mar 15, 2019
Slides: 9 pages
Slide Content
Binary Semaphore Manash Kumar Mondal Department of Computer Science & Engineering University of Kalyani
Semaphore A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multitasking operating system. The semaphore concept was invented by Dutch computer scientist Edsger Dijkstra in 1962 or 1963 A semaphore is simply a variable. 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 2
Type of Semaphore Semaphores which allow an arbitrary resource count are called counting semaphores. Counting semaphore can take non-negative integer values Semaphores which are restricted to the values 0 and 1 (or locked/unlocked, unavailable/available) are called binary semaphores and are used to implement locks. 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 3
Operations in Semaphore Two operations Down or P or Wait Decrease the value of semaphore variable Up or V or Signal Increase the Value of semaphore variable 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 4
Down Operation Down(Semaphore S ) { if( S value == 1) { S value=0; // Successful operation } else{ Block this process and place in suspended list, Sleep(); } } 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 5
Up Operation Up (Semaphore S ) { if(Suspend list is Empty) { S value=1; } else{ Select a process from suspended list and , Wakeup(); } } 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 6
Down and Up Operations Down(Semaphore S ) { if( S value == 1) { S value=0; // Successful operation } else{ Block this process and place in suspended list, Sleep(); } } 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 7 Up (Semaphore S ) { if(Suspend list is Empty) { S value=1; } else{ Select a process from suspended list and , Wakeup(); } }
Example Up (Semaphore S ) { if(Suspend list is Empty) { S value=1; } else{ Select a process from suspended list and , Wakeup(); } } 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 8 Down(Semaphore S ) { if( S value == 1) { S value=0; // Successful operation } else{ Block this process and place in suspended list, Sleep(); } } Lets two process P1 and P2 wants to access critical section P1 P2 Down(S) Down(S) Critical section Critical section Up(S) Up(S)
Thank You 16-Mar-19 KUCSE, Manash Kr. Mondal, M.Tech 9