pthread_join

David Xu davidxu at freebsd.org
Mon Apr 28 00:39:32 PDT 2003


----- Original Message ----- 
From: "Daniel Eischen" <eischen at pcnet1.pcnet.com>
To: "David Xu" <davidxu at viatech.com.cn>
Cc: <freebsd-threads at freebsd.org>
Sent: Monday, April 28, 2003 12:58 PM
Subject: Re: pthread_join


> On Mon, 28 Apr 2003, David Xu wrote:
> 
> > In thr_cleanup(),  joinee accesses joiner without holding joiner's sched lock,
> > it is possible when joinee accesses joiner, the joiner may disappear (canceled).
> > 
> > if ((joiner->state == PS_JOIN) &&
> >     (joiner->join_status.thread == thread)) {
> > joiner->join_status.thread = NULL;
> 
> Yes, when canceling we need to take the joinee's scheduling lock.
> I think we need to add a reference to the thread so it doesn't go
> away while we release the current lock and take the joiner's lock.
> I think processing the joiner can be done in pthread_exit() instead
> of thr_cleanup().  That's the way libc_r does it; I moved it
> into thr_kern in libpthread, but it doesn't need to be there.
> 
> We could also have another lock just for joins.  Or use each
> thread's lock.  Each thread has a lock, similar to proc lock
> in the kernel, but they're not currently used for anything yet.
> I envisioned using the proc lock whenever we needed to modify
> something in the thread, but just used the scheduling locks
> because it was easier.
> 
> I'm working on some signal fixes and some other fixes to
> hopefully fix your SMP problems.  I want to try these fixes
> before making _thr_sched_switch() atomic (your SMP changes).
> 
My change to atomic _thr_sched_switch does not add overhead,
it just enters critical region ealier than current code, but
total number of lock and critical region is same as current
code, and gains reliable result.


> -- 
> Dan Eischen



More information about the freebsd-threads mailing list