Consider the following program:
const int n = 50;
int tally;
void total() {
int count;
for (count = 1; count <= n; count++){
tally++;
}
}
void main() {
tally = 0;
parbegin (total (), total ());
write (tally);
}
Determine the proper lower bound and upper bound on the final value of the shared variable tally output by this concurrent program.Assume processes can execute at any relative speed and that a value can only be incremented after it has been loaded into a register by a separate machine instruction.
Suppose that an arbitrary number of these processes are permitted to execute in parallel under the assumptions of part (a).What effect will this modification have on the range of final values of tally?
My problem is that I don't understand the question what does this mean ?
... and that a value can only be incremented after it has been loaded into a register by a separate machine instruction.
I feel that when two processes execute simultaneously due to this assumption some value of tally will be lost but I don't know how it can happen because I don't know what this assumption means so I can't find lower bound!it is obvious that if 2 or n process execute one after the other tally will be 100 hence 100 = (number of process *50) is upper bound!
++
operator into multiple instructions. Firsttally
gets loaded into a local processor register, then the register gets incremented, eventually the value gets stored back to memory. It is unspecified in this problem what exactly the compiler did. It might be storing the value of the register back into the memory location fortally
after each iteration of the loop, or it might just be doing the store once, after all 50 increments have occurred. It's also unspecified whether each process readstally
from memory once or 50 times. $\endgroup$