From owner-freebsd-threads@FreeBSD.ORG Mon Apr 28 00:39:32 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0C62E37B401 for ; Mon, 28 Apr 2003 00:39:32 -0700 (PDT) Received: from exchhz01.viatech.com.cn (ip-167-164-97-218.anlai.com [218.97.164.167]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0CD2C43F75 for ; Mon, 28 Apr 2003 00:39:30 -0700 (PDT) (envelope-from davidxu@freebsd.org) Received: from davidw2k (ip-240-1-168-192.rev.dyxnet.com [192.168.1.240]) by exchhz01.viatech.com.cn with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id JM649LCP; Mon, 28 Apr 2003 15:24:54 +0800 Message-ID: <001001c30d59$913d25e0$f001a8c0@davidw2k> From: "David Xu" To: "Daniel Eischen" References: Date: Mon, 28 Apr 2003 15:38:19 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 cc: freebsd-threads@freebsd.org Subject: Re: pthread_join X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Apr 2003 07:39:32 -0000 ----- Original Message -----=20 From: "Daniel Eischen" To: "David Xu" Cc: Sent: Monday, April 28, 2003 12:58 PM Subject: Re: pthread_join > On Mon, 28 Apr 2003, David Xu wrote: >=20 > > In thr_cleanup(), joinee accesses joiner without holding joiner's = sched lock, > > it is possible when joinee accesses joiner, the joiner may disappear = (canceled). > >=20 > > if ((joiner->state =3D=3D PS_JOIN) && > > (joiner->join_status.thread =3D=3D thread)) { > > joiner->join_status.thread =3D NULL; >=20 > 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. >=20 > 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. >=20 > 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). >=20 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. > --=20 > Dan Eischen