From owner-freebsd-threads@FreeBSD.ORG Thu Feb 19 05:48:15 2004 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 4B5F316A4D0 for ; Thu, 19 Feb 2004 05:48:15 -0800 (PST) Received: from smtp02.syd.iprimus.net.au (smtp02.syd.iprimus.net.au [210.50.76.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 20FFD43D1D for ; Thu, 19 Feb 2004 05:48:15 -0800 (PST) (envelope-from tim@robbins.dropbear.id.au) Received: from robbins.dropbear.id.au (210.50.217.1) by smtp02.syd.iprimus.net.au (7.0.024) id 402CF87000199257; Fri, 20 Feb 2004 00:48:13 +1100 Received: by robbins.dropbear.id.au (Postfix, from userid 1000) id 6D96341C0; Fri, 20 Feb 2004 00:47:33 +1100 (EST) Date: Fri, 20 Feb 2004 00:47:33 +1100 From: Tim Robbins To: Mike Makonnen Message-ID: <20040219134733.GA38023@cat.robbins.dropbear.id.au> References: <20040219062850.GC1074@mobile.acs-et.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040219062850.GC1074@mobile.acs-et.com> User-Agent: Mutt/1.4.1i cc: freebsd-threads@freebsd.org Subject: Re: libthr patch 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: Thu, 19 Feb 2004 13:48:15 -0000 On Thu, Feb 19, 2004 at 09:28:50AM +0300, Mike Makonnen wrote: > Index: sys/kern/kern_thr.c [...] > +int > +thr_wake(struct thread *td, struct thr_wake_args *uap) > + /* thr_id_t id */ > +{ > + PROC_LOCK(((struct thread *)uap->id)->td_proc); > + ((struct thread *)uap->id)->td_lthrflags |= LTF_THRWAKEUP; > + PROC_UNLOCK(((struct thread *)uap->id)->td_proc); > + wakeup_one((void *)uap->id); > + return (0); > +} [...] Make sure you fix thr_wake() to check that uap->id is valid before you commit this patch. Something like this would be safer but slower: struct thread *td1; PROC_LOCK(td->td_proc); FOREACH_THREAD_IN_PROC(td->td_proc, td1) if (td1 == (struct thread *)uap->id) break; if (td1 == NULL) { PROC_UNLOCK(td->td_proc); return (ESRCH); } td1->td_lthrflags |= LTF_THRWAKEUP; wakeup_one(td1); PROC_UNLOCK(td->td_proc); return (0); (I'm not sure that it's safe to call wakeup_one() on a thread pointer that isn't curthread without holding the proc lock, so I changed that too.) Tim