Question

In: Computer Science

select one of the below process synchronization problem and describe the problem and its solution 1)...

select one of the below process synchronization problem and describe the problem and its solution

1) producer - consumer problem
2) the dining - philosophers problem
3) reader - writer problem
4) sleeping barber problem

Solutions

Expert Solution

​​​​​​Selecting producer consumer problem for answering from these synchronization problem

1) Producer - consumer problem

Producer consumer problem is a classic synchronization problem. The problem can be solved by using semaphores.

Problem statement

We have a buffer of fixed size. A producer produces an item and place it on the buffer. A consumer takes the item from the buffer and consumes it. We are in need to ensure that when the producer places an item the consumer should not consume any item at the same time. The buffer is the critical section in this problem.

To solve this two counting semaphores are used, full and empty. Full semaphore keep the number of items in buffer at any given time and empty semaphore keeps track of the number of unoccupied slots.

Semaphore

Semaphore S is an integer that can be accessed only through two standard operations: wait() and signal().

The wait() operation reduces the value by 1band signal() operation increases the value of semaphore by 1. It is depicted as follows in c program

wait(S)

{

whole(S<=0) ;

S--;

}

signal(S)

{

S++;

}

Semaphores are of two types, binary semaphore and counting semaphore.

Binary semaphore: It is smiliar to mutex lock and it can only have two values 0 and 1.wiyh value intialized to 1. It is used to implement the critical section problem with multiple processes.

Counting semaphore: It's value can range over a unrestricted domain. It is used to control access to a resource that has multiple instances.

Initilization of semaphores

mutex = 1

Full = 0 // Initially all slots are empty this full slots are zero

Empty = n // Initially all slots are empty

Solution for producer

do

{ // placing an item

wait(empty);

wait(mutex);

//place in buffer

signal(mutex);

signal(full);

}

while(true)

When producer produces an item the value of empty will reduced by 1 as an item occupy the empty space. The value of mutex is reduced to prevent the consumer from accessing the item in buffer bufffer. After the item is placed in buffer. The value of full and mutex is increased by 1. As now the item is available and it can be accessed by consumer.

Solution for consumer

do

{

wait(full) ;

wait(mutex) ; // remove item from buffer

signal(mutex) ;

signal(buffer) ; //consumes items

} while (true)

As the consumer is removing an item from buffer the value of full and mutex is also reduced by1, to prevent the producer from accessing the buffer. After that the value of empty is increased by 1 after the consumer consumes the item also the mutex is also increased by 1 as now producer can access the bufffer


Related Solutions

Solution for problem one (P1) below: ME 311 Thermodynamics I 1 Homework 5 Problem from Cengel...
Solution for problem one (P1) below: ME 311 Thermodynamics I 1 Homework 5 Problem from Cengel and Boles 8th Edition P1) Carbon dioxide flows steadily in a pipe at 3000 kPa, 31 °C, and at a rate of 1.5 kg/s. Determine the density of carbon dioxide using (a) the ideal gas law and (b) the compressibility chart.
Select a Product/Service and answer the below question. 1. Describe its Features and benefits. 2. Target...
Select a Product/Service and answer the below question. 1. Describe its Features and benefits. 2. Target Market - (Who is it intended for?) 3. Price - (What does it cost?) 4. Place - (Where can you buy it) 5. Promotion - (How can you find out more about it)
select o5 group of multicellular algae, and describe its life cycle. select one group of multicellular...
select o5 group of multicellular algae, and describe its life cycle. select one group of multicellular algae, and describe its life cycle.
Creativity is a process. As such there are certain elements that facilitate that process. Select one...
Creativity is a process. As such there are certain elements that facilitate that process. Select one of the elements of the creative process discussed in the readings. Analyze how your organization manages this process. For example, what techniques can be employed to ensure that this process works well when it comes to creativity. Include a link to at least one additional resource that supports your position
1) Find the solution of the given initial value problem and describe the behavior of the...
1) Find the solution of the given initial value problem and describe the behavior of the solution as t → +∞ y" + 4y' + 3y = 0, y(0) = 2, y'(0) = −1. 2) Find a differential equation whose general solution is Y=c1e2t + c2e-3t 3) Determine the longest interval in which the given initial value problem is certain to have a unique twice-differentiable solution. Do not attempt to find the solution t(t − 4)y" + 3ty' + 4y...
1 For the process 2F(g)→F2(g), Select one: a. ΔH is + and ΔS is + for...
1 For the process 2F(g)→F2(g), Select one: a. ΔH is + and ΔS is + for the reaction.ΔH is + and ΔS is + for the reaction. b. ΔH is + and ΔS= 0 for the reaction.ΔH is + and ΔS= 0 for the reaction. c. ΔH is – and ΔS is – for the reaction.ΔH is – and ΔS is – for the reaction. d. ΔH is – and ΔS is + for the reaction.ΔH is – and ΔS ...
Use the one solution given below to find the general solution of the differential equation below...
Use the one solution given below to find the general solution of the differential equation below by reduction of order method: (1 - 2x) y'' + 2y' + (2x - 3) y = 0 One solution: y1 = ex
Select one topic below.  Define it and discuss its relationship with stress and wellness according to research....
Select one topic below.  Define it and discuss its relationship with stress and wellness according to research. - Cognitive appraisal - Perceived control - Type A or Type B Personality - Lifestyle factors - Social support - Meditation - Faith - Alternative medicine - Type D Personality Useful links: https://www.youtube.com/watch?v=qzR62JJCMBQ https://www.youtube.com/watch?v=Aw71zanwMnY
A/1/The process of opsonisation of antigen particles involves: Select one: _ a. inhibition of viral replication...
A/1/The process of opsonisation of antigen particles involves: Select one: _ a. inhibition of viral replication b. chemotaxis c. coating bacteria with antibodies or complement component d. activation of natural killer (NK) cells e. cytokine production 2/Under resting conditions, most of the heat loss from the body occurs through: Select one: a. radiation b. sweating c. conduction d. convection 3/In the female reproductive cycle, the surge of luteinizing (LH) hormone leads to: Select one: a. ovulation L b. disintegration of...
Create a transportation problem Select an initial feasible solution ( any method). Solve the transportation problem...
Create a transportation problem Select an initial feasible solution ( any method). Solve the transportation problem using the method of multipliers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT