Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Following is the code for two threads T1 and T2: [executed once] int x = 0 // global shared variable T1: for (i=0; i++; i<100) x++; T2: x++ // no loop, just one increment The above code was given to students with the question “what is the final value of x, after both T1 and T2 finished executing.” Everyone answered by saying the value would be 100 or 101. One student answered, the value can be anything from 1 to 101. This person was right. Show how this is possible (Hint: Show how it can be 1).

Following is the code for two threadsT1 and T2: [executed once]int x = 0 // global shared

variable

T1:     for (i=0; i++; i<100) x++;

T2:     x++    // no loop, just one increment

The above code was given to students with the question “what is the final value of x, after both T1 and T2 finished executing.”

Everyone answered by saying the value would be 100 or 101.

One student answered, the value can be anything from 1 to 101. This person was right.

Show how this is possible (Hint: Show how it can be 1).

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"