Is there some way how to ensure that java flushes the cache of writes that have been done before the CyclicBarrier or CountDownLatch allows us to continue (as the synchronized keyword does) without using the synchronized keyword?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think it is already guaranteed by the API.
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CyclicBarrier.html
Memory consistency effects: Actions in a thread prior to calling await() happen-before actions that are part of the barrier action, which in turn happen-before actions following a successful return from the corresponding await() in other threads.
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/package-summary.html#MemoryVisibility
The results of a write by one thread are guaranteed to be visible to a read by another thread only if the write operation happens-before the read operation. … Actions prior to calling CyclicBarrier.await happen-before actions performed by the barrier action, and actions performed by the barrier action happen-before actions subsequent to a successful return from the corresponding await in other threads.
This means
no additional synchronization is needed;
read x2will see the result ofwrite x2