ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU-(2020-2021)-1 > student homework > 2018529627015_SIRLEAF_SIAKA_Joe >
Homework 6 Version 0
👤 Author: by shatino94163com 2020-12-22 05:47:59
Definition:

Semaphore is simply a variable which is non-negative and shared between threads. This variable is used to solve the critical section problem and to achieve process synchronization in the multiprocessing environment.

Semaphores in Process Synchronization


Semaphore was proposed by Dijkstra in 1965 which is a very significant technique to manage concurrent processes by using a simple integer value, which is known as a semaphore.

Semaphores are of two types:

 



    1. Binary Semaphore –This is also known as mutex lock. It can have only two values – 0 and 1. Its value is initialized to 1. It is used to implement the solution of critical section problem with multiple processes.




 

 

 



    1. Counting Semaphore –Its value can range over an unrestricted domain. It is used to control access to a resource that has multiple instances.




 

 

Bounded Buffer Problem


Bounded buffer problem, which is also called producer consumer problem, is one of the classic problems of synchronization. Let's start by understanding the problem here, before moving on to the solution and program code.

What is the Problem Statement?


There is a buffer of n slots and each slot is capable of storing one unit of data. There are two processes running, namely, producer and consumer, which are operating on

the buffer.


Here's a Solution


One solution of this problem is to use semaphores. The semaphores which will be used here are:

 



    • m, a binary semaphore which is used to acquire and release the lock.




 



    • empty, a counting semaphore whose initial value is the number of slots in the buffer, since, initially all slots are empty.




 



    • full, a counting semaphore whose initial value is 0.




 
At any instant, the current value of empty represents the number of empty slots in the buffer and full represents the number of occupied slots in the buffer.

Please login to reply. Login

Reversion History

Loading...
No reversions found.