[PATCH] Unify pthread_spin_[try]lock implementations.

David Miller davem@davemloft.net
Wed Jul 11 08:25:00 GMT 2012


From: Roland McGrath <roland@hack.frob.com>
Date: Wed, 11 Jul 2012 01:14:41 -0700 (PDT)

>> +int
>> +pthread_spin_lock (pthread_spinlock_t *lock)
>> +{
>> +  while (atomic_compare_and_exchange_val_acq (lock, 1, 0) != 0)
>> +    while (*lock != 0)
>> +      ;
> 
> What's the inner loop for?

I guess the idea is to spin with non-atomic reads when the lock is
contended so we don't do expensive bus cycles grabbing the cache line
in exclusive state over and over again.

If we spun using only the atomic it would be very expensive.



More information about the Libc-alpha mailing list