This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: malloc() and spinlocks
On Tue, Nov 26, 2002 at 05:56:30PM +0100, Wolfram Gloger wrote:
> Hi,
>
> > Generally the spinlock style locks perform better in threaded
> > applications on SMP hardware anyway. I'm not aware of the
> > motivations behind choosing the more heavy lock code,
>
> It was just portability.
>
> > but a
> > change to spinlocks probably won't hurt threaded applications.
>
> In fact, threaded applications will benefit just as non-threaded ones.
> It was unintentional that the spinlocks weren't enabled on ix86 in
> glibc.
?? Without thread-m.h assembly spinlocks the code is:
movl pthread_mutex_lock@GOT(%ebx), %eax
testl %eax, %eax
jne 1f
movl $1, %eax
movl %eax, mutexvar@GOTOFF(%ebx)
.subsection 1
1: something for -lpthread
.previous
Your spinlock code is longer, even if I change if (!r) to
if (!__builtin_expect(r, 0)) - because of the loop, mutexvar@GOTOFF(%ebx)
will be hoisted out of the loop, cnt register cleared, plus last time
I checked xchgl is more expensive than movl.
Jakub