Cheap and Secure Web Hosting Provider : See Now

executing threads with no synchronization

, , No Comments
Problem Detail: 

suppose Threads 1 and 2 are executing concurrently with shared integer variables A, B, and C. Thread 1 executes:A=4, B=5, C=B-A; Thread 2 executes: A=3, B=6, C=A+B;

I'm trying to find what can the possible values of C be after execution of this fragment when synchronization is not implemented.

I know if there is no synchronization then the reads see writes that occur later in the execution order and it will be counter intuitive ( execution will be happens-before consistency)

I am confused what can be the possible values of C. Can the possible values for C be 1,2,3,8,9,10 after substituting the all possible values for A & B from both thread 1 and thread 2 for C=B-A & C=A+B

Asked By : robert

Answered By : Yuval Filmus

Hint: Let $C = B \pm A$ be the final instruction being executed. Clearly $A \in \{3,4\}$ and $B \in \{5,6\}$, and this shows that $C \in \{1,2,3,8,9,10\}$. For the other direction, show that by carefully scheduling both threads, you can choose which of $C = B \pm A$ is executed last, and choose the value that $A$ and $B$ get prior to that instruction being executed.

Best Answer from StackOverflow

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

3200 people like this

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback