Thank you guys...
You can't have X1Y1 or similiar because the synchronized method will prevent that from happening.
Agree 100%, but what about:
X0Y1X2Y3X4Y5
Y0X1Y2X3Y4X5
Why can't it start with
Y? According to the answer, it
always starts with
X. Who is ensuring me that? The scheduler might say: "Ok, I have 2 threads,
t1 and t2, but just because I love
t2 I move this thread to running and leave
t1 in the runnable state.
Actually, if yield did release the lock, then MAYBE the values obtained could be X1Y1, such as if the thread yields after the local variable is set but before the member variable is incremented.
Exactly, and this is my confusion. I would say that the result is unpredictable..
yield might/might not occur.
correct me if I'm wrong.