Subject: Re: locking in pthread_detach function
To: Jan Kryl <loo@bazmek.net>
From: Andrew Doran <ad@netbsd.org>
List: tech-userlevel
Date: 08/23/2007 20:16:32
On Thu, Aug 23, 2007 at 05:26:31PM +0200, Jan Kryl wrote:
> I have found a weird code in libpthread, file pthread.c, function
> pthread_detach():
>
> ...
> pthread_spinlock(&self->pt_lock);
> thread->pt_flags |= PT_FLAG_DETACHED;
> pthread_spinunlock(&self->pt_lock);
> ...
>
> Shouldn't we use thread->pt_lock instead of self->pt_lock for locking?
> Or am I missing something?
Well spotted. I have checked in a fix. There is another problem, since both
the kernel and the thread library maintain a record of whether a thread is
detached or not. Those two records are not exactly in sync.
Andrew