Consider the following concurrent program running on a single processor machine in which a race condition can happen with the shared variable tally:
const int n = 50;
int tally;
void total() {
int count;
for (count=1; count<=n; count++)
tally++
}
void main() {
tally = 0;
// parbegin executes the functions concurrently
parbegin(total(),total());
output tally;
}

(a) What is the smallest possible value and the largest possible value of the shared variable tally in this concurrent program. Assume processes can execute at any relative speed and that the increment statement is broken into 3 instructions (load, add, store). Explain your answer.
(b) If we have k calls of the function total() in parbegin() as opposed to 2, what the smallest possible value and the largest possible value of the shared variable tally in this concurrent program? Explain your answer.

Respuesta :

ACCESS MORE