Question: Six drummers sit in a circle. Each drummer has a drum, along with a drumstick to their left and their right. Drummers go back and

Six drummers sit in a circle. Each drummer has a drum, along with a drumstick to their left and their right. Drummers go back and forth between brainstorming and drumming. However, they cannot drum unless they are holding each of the two drumsticks to their sides. Consider the following pseudocode which attempts to simulate drummers in such a way that enforces mutual exclusion of the drumsticks:
//array of 6 semaphores initialized to 1
Semaphore drumstick[6]={1,1,1,1,1,1};
void drummer(int i)
{
while(true)
{
brainstorm();
semWait(drumstick[i]);
semWait(drumstick[(i +1) mod 6]);
drum();
semWait(drumstick[(i +1) mod 6]);
semWait(drumstick[i]);
}
}
Void main()
{
parbegin(drummer(0), drummer(1), drummer(2), drummer(3), drummer(4) drummer(5)
}
Draw the resource allocation diagram
Could this lead to deadlock? Use your resource allocation diagram to justify your answer. Additionally, if it could lead to deadlock, describe how you would modify it so that deadlock is not possible

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!