[haiku-commits] Re: r36333 - in haiku/trunk: headers/posix src/system/libroot/posix/pthread

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 18 Apr 2010 11:42:15 +0200

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".

CU, Ingo

Other related posts: