Page 1 of 1
About Question enthuware.ocpjp.v7.2.1705 :
Posted: Wed Aug 07, 2013 3:15 pm
by jklb
Won't the "t.join()" assure that any modifications made by thread t will be seen by the main thread? Won't that assure the value of sum will be 20?
Re: About Question enthuware.ocpjp.v7.2.1705 :
Posted: Thu Aug 08, 2013 11:37 am
by admin
Yes, the join method provides
"happen-before" semantics so all updates made by thread t will be seen by the main thread.
But that is not the issue here. The issue is that the update itself is faulty. When thread t tries to update 'sum', it does not acquire the same lock that is used by the main thread. So this update may step on the main thread's update.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1705 :
Posted: Thu Aug 08, 2013 11:39 am
by admin
I see you are referring to the last part in the explanation. Yes, you are right. This should be fixed.
Thank you for your feedback.
-Paul.
Re: About Question enthuware.ocpjp.v7.2.1705 :
Posted: Thu Aug 08, 2013 1:11 pm
by jklb
Actually, I was confused and your response helped clarify my understanding. But improving the explanation would help because I didn't get it the first time.
Thank you.