I have a question regarding memory barriers when using the Condition provided by Lock .
As for the example provided in javadoc for Condition , I have a usage question:
int putptr, takeptr, count;
Should these attributes be declared unstable? As I understand from the example, the thread may not see modifications, for example, count .
Or, what, when signal() is called, all modifications made since the acquisition of the lock are visible to other threads? How is the code in a synchronized block?
If so, are the modifications visible when calling signal() or when unlock() is called in a lock?
Thanks.
Edit: I see in javadoc Lock :
All lock implementations must comply with the same memory synchronization semantics as the built-in monitor lock, as described in Section 17.4 of the Java ™ Language Specifications:
- A successful lock operation has the same memory synchronization effects as a successful lock action.
- A successful unlock operation has the same memory synchronization effects as a successful unlock action.
Failed lock and unlock operations and repeated lock / unlock operations do not require any memory synchronization effects.
They mean: “A successful lock operation has the same memory synchronization effects as entering a synchronized block,” and “A successful unlock operation has the same memory synchronization effects as exiting a synchronized block”?
Fbb
source share