> > On 2010-04-18 at 01:06:41 [+0200], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> > > wrote: > > ingo_weinhold@xxxxxx wrote: > > > +int > > > +pthread_spin_lock(pthread_spinlock_t* lock) > > > +{ > > > + while (atomic_test_and_set((int32*)&lock->lock, LOCKED, > > > UNLOCKED) == > LOCKED) > > > + ; // spin > > > + return 0; > > > +} > > > > Shouldn't it at least call thread_yield() here? > > I guess on UP machines that would definitely make sense. On SMP > machines > I'm not sure. I had a quick look at the NetBSD implementation and > they > simply spin, calling a pthread__smt_pause() macro which for x86[-64] > translates to "rep; nop". Intel suggests to use the PAUSE instruction in the optimization guide (3.4.1.2 in my version) it avoids a speed penalty due to a spurious memory order violation that may be generated when exiting the loop without the PAUSE instruction as a hint towards a spin-wait loop. We already use the PAUSE instruction in the kernel spinlocks. I think it is actually equivalent to "rep; nop" which'd explain the use in NetBSD. Regards Michael