[concurrency-interest] fast semaphore

Szabolcs Ferenczi szabolcs.ferenczi at gmail.com
Fri Apr 6 17:16:25 EDT 2007

On 05/04/07, Joseph Seigh <jseigh_cp00 at xemaps.com> wrote:
> Here's the fast pathed semaphore I used with ConcurrentLinkedQueue.

I have some comments about it.

If this semaphore is faster, I think, it is faster for a
release-acquire sequence. And it is faster because the check-and-swap
(CAS) operation on an atomic variable is faster than a corresponding
semaphore operation. This also means that in these cases the semaphore
operations are shortcutted or blocked by the CAS operations on an
atomic variable.

On the other hand, the `faster' semaphore is slower for the
acquire-release sequence because of the overhead of the shortcutting
wrapper code. However, in this case the delay is neglectable, since
the thread is suspended anyway.

So, it means that coding the blocking version of the
ConcurrentLinkedQueue with help of this variant of the semaphore has
some advantage only in the case when the consumer is not blocked.

Do you agree with my comments?

Best Regards,

More information about the Concurrency-interest mailing list