[erlang-questions] Lockfree now()

Wojtek Narczyński wojtek@REDACTED
Thu Jul 12 20:49:44 CEST 2012


On 07/12/2012 08:23 PM, Erik Søe Sørensen wrote:
> Because of atomic operations.
> I may not have been explicit enough there: latest_now is a 
> java.util.concurrent.AtomicLong, and the two updating accesses to it 
> are atomic.
>                 long prev;
>                 while ((prev = latest_now.get()) < micros) {
>                         if (latest_now.compareAndSet(prev,micros)) {
>                                 return micros;
>                         }
>                 }
>                 return latest_now.incrementAndGet();
>
> This - and only because of this - means that no lock is necessary.
Oh, I think I understand now.

You want to have one coarse-grained clock - protected by a lock, and 
another one fine-grained - updated atomically.

Do I understand correctly now?

--Regards,
Wojtek



More information about the erlang-questions mailing list