World's most popular travel blog for travel bloggers.

What does it mean that a value can only be incremented after it's been loaded into a register?

, , No Comments
Problem Detail: 

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); } 
  1. 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.

  2. 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!

Asked By : haleh

Answered By : haleh

if we suppose the processes P1 and P2,at first P1 executes. it increments tally to 1 but before it loads it to memory,it lose the processor,then P2 is processing and after 49 iteration it makes tally to 49 and stores it then it lose processor and again P1 is processing and store 1 to tally then lose processor and P2 load 1 to register and lose processor, P1 increment tally to 1+49 = 50(within 49 iteration) and tally = 50 ,then lose processor ,P2 increment the register which was 1 and loads 2 to tally and now it is complete and tally = 2 ; so answer is :

1.  2 <= tally <= 100 2.  2 <= tally <= 2*numbers of process 

.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/24255

0 comments:

Post a Comment

Let us know your responses and feedback