Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Describe briefly what happens in Msynch (written in Java) when the first thread calls acquire ( ) the first time and each time another thread

  • Describe briefly what happens in Msynch (written in Java) when the first thread calls acquire ( ) the first time and each time another thread calls replyReceived ( ).
  • Find 3 synchronization-related errors in Msynch1. (This can be done through line-by-line comparison.) Explain why each error will cause Msynch1 not to work.

class Msynch

{

int replies;

int currentState = 1;

synchronized void acquire ( )

{ // Called by thread wanting access to a critical section

while (currentState != 1) wait ( );

replies = 0; currentState = 2;

//

// (Here, 5 messages are sent)

//

while (replies < 5) wait ( ); // Await 5 replies

currentState = 3;

}

synchronized void replyReceived ( )

{ // Called by communication thread when reply is received

replies++;

notifyAll ( );

}

synchronized void release ( )

{ // Called by a thread releasing the critical section

currentState = 1;

notifyAll ( );

}

}

class Msynch1

{

int replies;

int currentState = 1;

synchronized void acquire ( )

{ // Called by thread wanting access to a critical section

while (currentState != 1) yield ( );

replies = 0;

currentState = 2;

//

// (Here, 5 messages are sent)

//

if (replies < 5) wait ( ); // Await 5 replies

currentState = 3;

}

synchronized void replyReceived ( )

{ // Called by communication thread when reply is received

replies++;

}

synchronized void release ( )

{ // Called by a thread releasing the critical section

currentState = 1;

notifyAll ( );

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

In Msynch when the first thread calls the acquire method for the first time it enters a synchronized block It checks the value of the currentState var... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions

Question

describe several successful positive work interventions.

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

In Exercises find dy/dx by implicit differentiation. xy - y = x

Answered: 1 week ago