# Multiple Threads and single target..

Abimaran Kugathasan
Ranch Hand
Posts: 2066
How to predict the output for the below question? I got it from Master Exam.. Please help!

1) It'll keep on printing values which show x and y always as equal and increasing by 1 at each line.
2) It'll keep on printing values which show x and y always as different.
3) Nothing can be said about the sequence of values.
4) It'll keep on printing values which show x and y always as equal and increasing but may increase more than 1 at each line.

I can tell that both values will in a increasing order, but, will they(x and y) be equal? In that question both increments(x++; y++;) in the same line.
And when I run it, both gave same value (when the incrementation is in the same line). But, If I insert those Line 01 and Line 02, They(x and y) differs.

How to approach these kind of question?

Devaka Cooray
ExamLab Creator
Marshal
Posts: 4329
238
Despite x++; and y++; were in the same line or not, both of those statements are subjected to simultaneous access by two threads. Thus we can NOT say that it should show x and y always as equal.

Devaka

Abimaran Kugathasan
Ranch Hand
Posts: 2066
So the answer is : Nothing can be said about the sequence of values? But we can sure that those value will be in a incrementing manner.