[concurrency-interest] fast semaphore

Gregg Wonderly gregg at cytetech.com
Thu Apr 5 10:47:32 EDT 2007



Joseph Seigh wrote:

>     public boolean tryAcquire() {
>         int    oldCount;
>        
>         do {
>             oldCount = count.get();
>         }
>         while (oldCount > 0 && !count.compareAndSet(oldCount, (oldCount - 1)));
>    
>         return (oldCount > 0);

Shouldn't this be oldCount >= 0 so that the aquire when oldCount == 1 works?

>     }

Gregg Wonderly



More information about the Concurrency-interest mailing list