This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Unify pthread_spin_[try]lock implementations.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]