[concurrency-interest] Does Semaphore have the same memory model visibility guarantees as synchronizing?

Kasper Nielsen kasper at kav.dk
Wed Sep 7 16:10:39 EDT 2011


On 07-09-2011 21:46, Victor Grazi wrote:
> Hi - The JMM guarantees that when a Thread A enters a block that is
> synchronized on some object, it is guaranteed to see anything that had
> been visible to another thread B when thread B was synchronized on the
> same object.
>
> ReentrantLock has the same characteristic.
>
> Is Semaphore required to have the same semantics?
>
> Thanks, Victor

 From Semaphore.java

Memory consistency effects: Actions in a thread prior to calling a 
"release" method such as release() happen-before actions following a 
successful "acquire" method such as acquire() in another thread.

So I guess the answer is yes.

- Kasper


More information about the Concurrency-interest mailing list