0
Hi, I’m studying for a college exam and I really need some help on one end. We are reading about mutual exclusion (in the topic of microservices), and given the following scheme:
In the communication between Reader and Processor, to obtain mutual exclusion in the Active MQ queue, the following code was used:
int vez;
boolean usarFilaActiveMQ[] = { false, false };
public void alocarFilaActiveMQ(int ServiceNumber)
{
int otherServiceNumber = 1 - ServiceNumber;
usarFilaActiveMQ[ServiceNumber] = true;
vez = ServiceNumber;
while ((vez == ServiceNumber) &&
(usarFilaActiveMQ[otherServiceNumber] == true));
}
public void liberarFilaActiveMQ(int ServiceNumber)
{
usarFilaActiveMQ[ServiceNumber] = false;
}
What is the purpose of doing time = Servicenumber; and within while test whether turn is equal to Servicenumber?
This algorithm does not seem correct, since while has no body in the function, in theory it does nothing. time = Servicenumber is an assignment and inside the while you make a comparison to check if the values are equal, probably to ensure that the value remains the same as when it was assigned in the previous instruction to the while loop.
– Diego Farias