From owner-freebsd-threads@FreeBSD.ORG Sun Mar 26 02:01:03 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 827EE16A422; Sun, 26 Mar 2006 02:01:03 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4434143D48; Sun, 26 Mar 2006 02:01:03 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from localhost.my.domain (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2Q2116O025838; Sun, 26 Mar 2006 02:01:02 GMT (envelope-from davidxu@freebsd.org) From: David Xu To: freebsd-threads@freebsd.org Date: Sun, 26 Mar 2006 10:00:51 +0800 User-Agent: KMail/1.8.2 References: <44215FE9.2070602@highway.ne.jp> <20060324084834.GE27116@deviant.kiev.zoral.com.ua> <20060325100729.00713045@kan.dnsalias.net> In-Reply-To: <20060325100729.00713045@kan.dnsalias.net> MIME-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200603261000.52100.davidxu@freebsd.org> Cc: freebsd-hackers@freebsd.org, Alexander Kabaev Subject: Re: [patch] Re: dlopen() and dlclose() are not MT-safe? YES, esp. for libthr X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Mar 2006 02:01:03 -0000 =D4=DA Saturday 25 March 2006 23:07=A3=ACAlexander Kabaev =D0=B4=B5=C0=A3=BA > The thread mask only makes sense when flags are per-thread. I meant > to use it to detect PLT recursions from locking primitives exported to > rtld by the threads library as those are not allowed and threads > implementations are required to take special care to provide only > self-contained locks.=20 >=20 > The 'default' lock implementation will not work with any library > other than libc_r, and even that holds true only for some definition of > "work". The dynamic loader never had a reliable locking and > furthermore, there was no way to make it work better without threading > library cooperation. This is why we came up with a set of callbacks > rtld expects every threading library to provide. libpthread was the > first where these callbacks were implemented. It comes as a surprise > that libthr did not have them, because David Xu was the one who did > most of the work on rtld locking callbacks in libpthread. >=20 > The def_thread_set_flag function use is racy and should be fixed. >=20 > --=20 > Alexander Kabaev I have fixed it in libthr yesterday, I think I must forgot to do it in the past. Regards, David Xu From owner-freebsd-threads@FreeBSD.ORG Mon Mar 27 11:03:13 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 2E96A16A41F for ; Mon, 27 Mar 2006 11:03:13 +0000 (UTC) (envelope-from owner-bugmaster@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E297243D46 for ; Mon, 27 Mar 2006 11:03:12 +0000 (GMT) (envelope-from owner-bugmaster@freebsd.org) Received: from freefall.freebsd.org (peter@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2RB3C72062425 for ; Mon, 27 Mar 2006 11:03:12 GMT (envelope-from owner-bugmaster@freebsd.org) Received: (from peter@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2RB3Bji062419 for freebsd-threads@freebsd.org; Mon, 27 Mar 2006 11:03:11 GMT (envelope-from owner-bugmaster@freebsd.org) Date: Mon, 27 Mar 2006 11:03:11 GMT Message-Id: <200603271103.k2RB3Bji062419@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: peter set sender to owner-bugmaster@freebsd.org using -f From: FreeBSD bugmaster To: freebsd-threads@FreeBSD.org Cc: Subject: Current problem reports assigned to you X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2006 11:03:13 -0000 Current FreeBSD problem reports Critical problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2005/01/26] threads/76690threads fork hang in child for (-lc_r & -lthr) 1 problem total. Serious problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2000/07/18] kern/20016 threads pthreads: Cannot set scheduling timer/Can o [2000/08/26] kern/20861 threads libc_r does not honor socket timeouts o [2001/01/20] threads/24472threads libc_r does not honor SO_SNDTIMEO/SO_RCVT o [2001/01/25] threads/24632threads libc_r delicate deviation from libc in ha o [2001/01/25] kern/24641 threads pthread_rwlock_rdlock can deadlock o [2001/11/26] bin/32295 threads pthread dont dequeue signals o [2002/02/01] threads/34536threads accept() blocks other threads o [2002/05/25] kern/38549 threads the procces compiled whith pthread stoppe o [2002/06/27] threads/39922threads [threads] [patch] Threaded applications e o [2002/08/04] kern/41331 threads Pthread library open sets O_NONBLOCK flag o [2003/03/02] threads/48856threads Setting SIGCHLD to SIG_IGN still leaves z o [2003/03/10] threads/49087threads Signals lost in programs linked with libc s [2004/03/15] kern/64313 threads FreeBSD (OpenBSD) pthread implicit set/un o [2004/08/26] threads/70975threads unexpected and unreliable behaviour when o [2004/10/05] threads/72353threads Assertion fails in /usr/src/lib/libpthrea o [2004/10/07] threads/72429threads threads blocked in stdio (fgets, etc) are o [2004/10/21] threads/72953threads fork() unblocks blocked signals w/o PTHRE o [2004/12/19] threads/75273threads FBSD 5.3 libpthread (KSE) bug o [2004/12/21] threads/75374threads pthread_kill() ignores SA_SIGINFO flag o [2005/01/26] threads/76694threads fork cause hang in dup()/close() function p [2005/03/10] threads/78660threads Java hangs unkillably in STOP state after o [2005/04/08] threads/79683threads svctcp_create() fails if multiple threads o [2005/04/28] threads/80435threads panic on high loads o [2005/05/19] threads/81258threads Thread specific data is sometimes assigne o [2005/07/22] threads/83914threads [libc] popen() doesn't work in static thr o [2005/08/02] threads/84483threads problems with devel/nspr and -lc_r on 4.x o [2005/08/20] threads/85160threads [libthr] [patch] libobjc + libpthread/lib p [2005/11/19] threads/89262threads [kernel] [patch] multi-threaded process h o [2005/12/12] threads/90278threads libthr, ULE and -current produces >100% W o [2006/01/03] kern/91266 threads [threads] Trying sleep, but thread marked o [2006/03/07] threads/94176threads KSE: sigwait doesn't recieve SIGWINCH sen o [2006/03/15] threads/94467threads send(), sendto() and sendmsg() are not co 32 problems total. Non-critical problems S Submitted Tracker Resp. Description ------------------------------------------------------------------------------- o [2000/06/13] kern/19247 threads uthread_sigaction.c does not do anything o [2000/10/21] kern/22190 threads A threaded read(2) from a socketpair(2) f o [2001/09/09] threads/30464threads pthread mutex attributes -- pshared o [2002/05/02] threads/37676threads libc_r: msgsnd(), msgrcv(), pread(), pwri s [2002/07/16] threads/40671threads pthread_cancel doesn't remove thread from o [2004/07/13] threads/69020threads pthreads library leaks _gc_mutex o [2004/09/21] threads/71966threads Mlnet Core Dumped : Fatal error '_pq_inse o [2004/11/21] threads/74180threads KSE problem. Applications those riched ma o [2005/04/13] threads/79887threads [patch] freopen() isn't thread-safe o [2005/05/13] threads/80992threads abort() sometimes not caught by gdb depen o [2005/05/26] threads/81534threads [libc_r] [patch] libc_r close() will fail 11 problems total. From owner-freebsd-threads@FreeBSD.ORG Tue Mar 28 20:06:25 2006 Return-Path: X-Original-To: threads@FreeBSD.org 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 BC4C416A400; Tue, 28 Mar 2006 20:06:25 +0000 (UTC) (envelope-from kris@obsecurity.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6E00C43D70; Tue, 28 Mar 2006 20:06:25 +0000 (GMT) (envelope-from kris@obsecurity.org) Received: from obsecurity.dyndns.org (elvis.mu.org [192.203.228.196]) by elvis.mu.org (Postfix) with ESMTP id 301131A4DBB; Tue, 28 Mar 2006 12:06:25 -0800 (PST) Received: by obsecurity.dyndns.org (Postfix, from userid 1000) id 80C3D51406; Tue, 28 Mar 2006 15:06:24 -0500 (EST) Date: Tue, 28 Mar 2006 15:06:24 -0500 From: Kris Kennaway To: amd64@FreeBSD.org Message-ID: <20060328200624.GA10800@xor.obsecurity.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qDbXVdCdHGoSgWSk" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Cc: threads@FreeBSD.org Subject: libpthread compile failure X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Mar 2006 20:06:25 -0000 --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 7.0 during buildworld: /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting types for '_pthread_barrier_init' /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous declaration of '_pthread_barrier_init' was here /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting types for '_pthread_barrier_init' /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous declaration of '_pthread_barrier_init' was here *** Error code 1 Those two declarations are: > int > _pthread_barrier_init(pthread_barrier_t *barrier, > const pthread_barrierattr_t *attr, int count) > int pthread_barrier_init(pthread_barrier_t *, > const pthread_barrierattr_t *, unsigned); What is odd is that I can't see how this suddenly broke. Kris --qDbXVdCdHGoSgWSk Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (FreeBSD) iD8DBQFEKZc/Wry0BWjoQKURAgKYAKC4hKSq0jxYgPTu20Yq+iiOxBTMRgCfemm7 blr4fpE/tZatgTYIWPpmQHk= =0yOd -----END PGP SIGNATURE----- --qDbXVdCdHGoSgWSk-- From owner-freebsd-threads@FreeBSD.ORG Tue Mar 28 21:09:11 2006 Return-Path: X-Original-To: threads@freebsd.org 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 75E0616A422; Tue, 28 Mar 2006 21:09:11 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 14B75444A4; Tue, 28 Mar 2006 21:09:10 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.6/8.13.6/NETPLEX) with ESMTP id k2SL9AQ1011959; Tue, 28 Mar 2006 16:09:10 -0500 (EST) Date: Tue, 28 Mar 2006 16:09:10 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Kris Kennaway In-Reply-To: <20060328200624.GA10800@xor.obsecurity.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: amd64@freebsd.org, threads@freebsd.org Subject: Re: libpthread compile failure X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Mar 2006 21:09:11 -0000 On Tue, 28 Mar 2006, Kris Kennaway wrote: > On 7.0 during buildworld: > > /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting types for '_pthread_barrier_init' > /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous declaration of '_pthread_barrier_init' was here > /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting types for '_pthread_barrier_init' > /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous declaration of '_pthread_barrier_init' was here > *** Error code 1 > > Those two declarations are: > > > int > > _pthread_barrier_init(pthread_barrier_t *barrier, > > const pthread_barrierattr_t *attr, int count) > > > int pthread_barrier_init(pthread_barrier_t *, > > const pthread_barrierattr_t *, unsigned); > > What is odd is that I can't see how this suddenly broke. I just applied a fix to this. I'm not sure if this will be the only bug you find though (I haven't had a chance to test it with the recent namespace.h changes). -- DE From owner-freebsd-threads@FreeBSD.ORG Tue Mar 28 21:12:33 2006 Return-Path: X-Original-To: threads@freebsd.org 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 0A1EB16A400; Tue, 28 Mar 2006 21:12:33 +0000 (UTC) (envelope-from kris@obsecurity.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id B86DC444A8; Tue, 28 Mar 2006 21:12:32 +0000 (GMT) (envelope-from kris@obsecurity.org) Received: from obsecurity.dyndns.org (elvis.mu.org [192.203.228.196]) by elvis.mu.org (Postfix) with ESMTP id A13241A4DC4; Tue, 28 Mar 2006 13:12:32 -0800 (PST) Received: by obsecurity.dyndns.org (Postfix, from userid 1000) id 00495516BF; Tue, 28 Mar 2006 16:12:31 -0500 (EST) Date: Tue, 28 Mar 2006 16:12:31 -0500 From: Kris Kennaway To: Daniel Eischen Message-ID: <20060328211231.GB1968@xor.obsecurity.org> References: <20060328200624.GA10800@xor.obsecurity.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3lcZGd9BuhuYXNfi" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i Cc: amd64@freebsd.org, threads@freebsd.org, Kris Kennaway Subject: Re: libpthread compile failure X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Mar 2006 21:12:33 -0000 --3lcZGd9BuhuYXNfi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 28, 2006 at 04:09:10PM -0500, Daniel Eischen wrote: > On Tue, 28 Mar 2006, Kris Kennaway wrote: >=20 > > On 7.0 during buildworld: > > > > /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting typ= es for '_pthread_barrier_init' > > /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous de= claration of '_pthread_barrier_init' was here > > /usr/src/lib/libpthread/thread/thr_barrier.c:69: error: conflicting typ= es for '_pthread_barrier_init' > > /usr/src/lib/libpthread/../../include/pthread.h:156: error: previous de= claration of '_pthread_barrier_init' was here > > *** Error code 1 > > > > Those two declarations are: > > > > > int > > > _pthread_barrier_init(pthread_barrier_t *barrier, > > > const pthread_barrierattr_t *attr, int count) > > > > > int pthread_barrier_init(pthread_barrier_t *, > > > const pthread_barrierattr_t *, unsigned); > > > > What is odd is that I can't see how this suddenly broke. >=20 > I just applied a fix to this. I'm not sure if this will be the > only bug you find though (I haven't had a chance to test it > with the recent namespace.h changes). Thanks, I'll let you know. Kris --3lcZGd9BuhuYXNfi Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (FreeBSD) iD8DBQFEKaa/Wry0BWjoQKURAqY1AJ4w8l+uK0eoxpNFpTpYcdGS4ZIqUQCfdS15 8mG90c/0RYSEjKTioThPWto= =J3oG -----END PGP SIGNATURE----- --3lcZGd9BuhuYXNfi-- From owner-freebsd-threads@FreeBSD.ORG Wed Mar 29 06:48:03 2006 Return-Path: X-Original-To: threads@freebsd.org 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 1AF4116A400; Wed, 29 Mar 2006 06:48:03 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id BAC4443D48; Wed, 29 Mar 2006 06:48:00 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 825A12096; Wed, 29 Mar 2006 08:47:41 +0200 (CEST) X-Spam-Tests: AWL,BAYES_00,FORGED_RCVD_HELO X-Spam-Learn: ham X-Spam-Score: -2.4/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on tim.des.no Received: from xps.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id CFF102081; Wed, 29 Mar 2006 08:47:40 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id C321F33C8D; Wed, 29 Mar 2006 08:47:40 +0200 (CEST) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: threads@freebsd.org Date: Wed, 29 Mar 2006 08:47:40 +0200 Message-ID: <86slp1u4qb.fsf@xps.des.no> User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Cc: jeff@freebsd.org, davidxu@freebsd.org Subject: libthr cleanup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2006 06:48:03 -0000 --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable The attached patch brings libthr up to WARNS level 2. There is also a small amount of style and whitespace changes mixed in, mostly because I'm so conditioned to style(9) that my fingers sometimes do these things automatically. Parts of the patch go a little further than level 2, but we're nowhere near level 3 (or antything higher). The major obstacle is the umtx interface, which in my eyes is fundamentally broken. The _umtx_op() syscall is intended to replace _umtx_lock() and _umtx_unlock(), and support other operations like sleep, wakeup etc. This is the wrong way to go. If we applied this kind of thinking universally, we'd just define all our system calls as macro wrappers for __syscall(). Beyond these purely philosophical aspects, _umtx_op() seems designed to encourage poor coding practices. It's impossible to use in a type- safe manner: its first argument is supposed to be a struct umtx *, but I don't think there's a single instance in libthr where it is called with an actual struct umtx *. Instead, libthr uses umtx_t, which is defined as long. Sometimes, an umtx_t is passed as the third argument to _umtx_op() as well. Various fields in struct pthread, struct pthread_barrier and struct pthread_cond are declared as umtx_t. Some are used purely as cookies for passing to _umtx_op(); some are used as counters or state variables. It's a miracle libthr works at all. The kernel expects a pointer to a struct umtx; instead, it gets (mostly) a pointer to long. Luckily, struct umtx (which contains a single pointer) is the same size as long on all our platforms. _umtx_op() needs to be split into four system calls: int _umtx_lock_timeout(struct umtx *mtx, const struct timespec * __restrict timeout); int _umtx_unlock(struct umtx *mtx); int _umtx_wait_timeout(const void *cookie, struct umtx *mtx, const struct timespec * __restrict timeout); int _umtx_wake(const void *cookie); _umtx_unlock() already exists with the correct semantics; the rest are new. Note that we can't just add a struct timespec to _umtx_lock(), as that would break the upgrade path from RELENG_5; hence the _timeout suffix. I'm not sure the current implementation of UMTX_OP_WAIT / UMTX_OP_WAKE in the kernel is correct. Normally, a wait primitive (like msleep(), pthread_cond_wait() etc.) takes a cookie and a mutex, and unlocks the mutex while it's sleeping on the cookie. It looks like the umtx code originally worked like this, but I'm not sure it does anymore; it's hard to unravel, partly because I haven't quite figured out the queues yet and partly because I haven't had breakfast. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=libthr.diff Index: Makefile =================================================================== RCS file: /home/ncvs/src/lib/libthr/Makefile,v retrieving revision 1.18 diff -u -r1.18 Makefile --- Makefile 27 Mar 2006 05:58:58 -0000 1.18 +++ Makefile 28 Mar 2006 18:45:36 -0000 @@ -29,8 +29,8 @@ MAN= libthr.3 # enable extra internal consistancy checks -CFLAGS+=-D_PTHREADS_INVARIANTS -Wall -#CFLAGS+=-g +CFLAGS+=-D_PTHREADS_INVARIANTS +WARNS?=2 PRECIOUSLIB= Index: sys/thr_error.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/sys/thr_error.c,v retrieving revision 1.2 diff -u -r1.2 thr_error.c --- sys/thr_error.c 2 Apr 2005 01:20:00 -0000 1.2 +++ sys/thr_error.c 28 Mar 2006 18:12:41 -0000 @@ -36,7 +36,6 @@ #include -#include "libc_private.h" #include "thr_private.h" #undef errno Index: thread/thr_atfork.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_atfork.c,v retrieving revision 1.2 diff -u -r1.2 thr_atfork.c --- thread/thr_atfork.c 2 Apr 2005 01:20:00 -0000 1.2 +++ thread/thr_atfork.c 28 Mar 2006 18:12:41 -0000 @@ -26,10 +26,14 @@ * $FreeBSD: src/lib/libthr/thread/thr_atfork.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" +#include #include -#include #include -#include +#include +#include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_atfork, pthread_atfork); Index: thread/thr_attr.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_attr.c,v retrieving revision 1.4 diff -u -r1.4 thr_attr.c --- thread/thr_attr.c 9 Jan 2006 03:59:51 -0000 1.4 +++ thread/thr_attr.c 28 Mar 2006 18:12:41 -0000 @@ -96,11 +96,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_attr.c,v 1.4 2006/01/09 03:59:51 davidxu Exp $ */ +#include "namespace.h" #include #include +#include #include #include -#include +#include "un-namespace.h" #include "thr_private.h" @@ -326,12 +328,12 @@ _thr_check_init(); /* Allocate memory for the attribute object: */ - if ((pattr = (pthread_attr_t) malloc(sizeof(struct pthread_attr))) == NULL) + if ((pattr = malloc(sizeof(*pattr))) == NULL) /* Insufficient memory: */ ret = ENOMEM; else { /* Initialise the attribute object with the defaults: */ - memcpy(pattr, &_pthread_attr_default, sizeof(struct pthread_attr)); + memcpy(pattr, &_pthread_attr_default, sizeof(*pattr)); /* Return a pointer to the attribute object: */ *attr = pattr; Index: thread/thr_autoinit.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_autoinit.c,v retrieving revision 1.2 diff -u -r1.2 thr_autoinit.c --- thread/thr_autoinit.c 23 May 2003 09:48:20 -0000 1.2 +++ thread/thr_autoinit.c 28 Mar 2006 18:12:41 -0000 @@ -33,8 +33,6 @@ * $FreeBSD: src/lib/libthr/thread/thr_autoinit.c,v 1.2 2003/05/23 09:48:20 mtm Exp $ */ -#include - #include "thr_private.h" /* Index: thread/thr_barrier.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_barrier.c,v retrieving revision 1.4 diff -u -r1.4 thr_barrier.c --- thread/thr_barrier.c 4 Apr 2005 23:43:53 -0000 1.4 +++ thread/thr_barrier.c 28 Mar 2006 18:12:41 -0000 @@ -26,9 +26,11 @@ * $FreeBSD: src/lib/libthr/thread/thr_barrier.c,v 1.4 2005/04/04 23:43:53 davidxu Exp $ */ +#include "namespace.h" #include -#include #include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -54,10 +56,12 @@ int _pthread_barrier_init(pthread_barrier_t *barrier, - const pthread_barrierattr_t *attr, int count) + const pthread_barrierattr_t *attr, unsigned int count) { pthread_barrier_t bar; + (void)attr; + if (barrier == NULL || count <= 0) return (EINVAL); Index: thread/thr_barrierattr.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_barrierattr.c,v retrieving revision 1.2 diff -u -r1.2 thr_barrierattr.c --- thread/thr_barrierattr.c 2 Apr 2005 01:20:00 -0000 1.2 +++ thread/thr_barrierattr.c 28 Mar 2006 18:12:41 -0000 @@ -28,9 +28,11 @@ * $FreeBSD: src/lib/libthr/thread/thr_barrierattr.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include -#include #include +#include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_cancel.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_cancel.c,v retrieving revision 1.12 diff -u -r1.12 thr_cancel.c --- thread/thr_cancel.c 25 Mar 2006 07:03:13 -0000 1.12 +++ thread/thr_cancel.c 28 Mar 2006 18:12:41 -0000 @@ -27,7 +27,9 @@ * */ +#include "namespace.h" #include +#include "un-namespace.h" #include "thr_private.h" @@ -78,7 +80,7 @@ newval = curthread->cancelflags; if (SHOULD_CANCEL(newval) && !THR_IN_CRITICAL(curthread)) - pthread_exit(PTHREAD_CANCELED); + _pthread_exit(PTHREAD_CANCELED); } int Index: thread/thr_clean.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_clean.c,v retrieving revision 1.3 diff -u -r1.3 thr_clean.c --- thread/thr_clean.c 2 Apr 2005 01:20:00 -0000 1.3 +++ thread/thr_clean.c 28 Mar 2006 18:12:41 -0000 @@ -32,10 +32,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_clean.c,v 1.3 2005/04/02 01:20:00 davidxu Exp $ */ -#include +#include "namespace.h" +#include #include -#include #include +#include +#include +#include "namespace.h" #include "thr_private.h" Index: thread/thr_concurrency.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_concurrency.c,v retrieving revision 1.2 diff -u -r1.2 thr_concurrency.c --- thread/thr_concurrency.c 2 Apr 2005 01:20:00 -0000 1.2 +++ thread/thr_concurrency.c 28 Mar 2006 18:12:41 -0000 @@ -32,8 +32,10 @@ * $FreeBSD: src/lib/libthr/thread/thr_concurrency.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_cond.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_cond.c,v retrieving revision 1.16 diff -u -r1.16 thr_cond.c --- thread/thr_cond.c 2 Apr 2005 01:20:00 -0000 1.16 +++ thread/thr_cond.c 28 Mar 2006 18:12:41 -0000 @@ -26,11 +26,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_cond.c,v 1.16 2005/04/02 01:20:00 davidxu Exp $ */ -#include +#include "namespace.h" #include -#include -#include #include +#include +#include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -46,7 +48,11 @@ * Double underscore versions are cancellation points. Single underscore * versions are not and are provided for libc internal usage (which * shouldn't introduce cancellation points). + * XXX a sane person would have done it the other way around. */ +int __pthread_cond_timedwait(pthread_cond_t *, + pthread_mutex_t *, const struct timespec *); +int __pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); __weak_reference(__pthread_cond_wait, pthread_cond_wait); __weak_reference(__pthread_cond_timedwait, pthread_cond_timedwait); Index: thread/thr_condattr.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_condattr.c,v retrieving revision 1.1 diff -u -r1.1 thr_condattr.c --- thread/thr_condattr.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_condattr.c 28 Mar 2006 18:12:41 -0000 @@ -32,10 +32,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_condattr.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ -#include -#include +#include "namespace.h" #include #include +#include +#include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_create.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_create.c,v retrieving revision 1.28 diff -u -r1.28 thr_create.c --- thread/thr_create.c 27 Mar 2006 23:50:21 -0000 1.28 +++ thread/thr_create.c 28 Mar 2006 18:12:41 -0000 @@ -27,13 +27,18 @@ * $FreeBSD: src/lib/libthr/thread/thr_create.c,v 1.28 2006/03/27 23:50:21 davidxu Exp $ */ +#include "namespace.h" #include #include +#include +#include #include +#include +#include +#include #include #include -#include -#include +#include "un-namespace.h" #include "thr_private.h" @@ -230,7 +235,7 @@ * Parent thread have stored signal mask for us, * we should restore it now. */ - sigprocmask(SIG_SETMASK, &set, NULL); + __sys_sigprocmask(SIG_SETMASK, &set, NULL); } /* @@ -242,7 +247,7 @@ THR_UNLOCK(curthread); /* Run the current thread's start routine with argument: */ - pthread_exit(curthread->start_routine(curthread->arg)); + _pthread_exit(curthread->start_routine(curthread->arg)); /* This point should never be reached. */ PANIC("Thread has resumed after exit"); Index: thread/thr_detach.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_detach.c,v retrieving revision 1.10 diff -u -r1.10 thr_detach.c --- thread/thr_detach.c 17 Dec 2005 09:42:45 -0000 1.10 +++ thread/thr_detach.c 28 Mar 2006 18:12:41 -0000 @@ -28,9 +28,11 @@ * */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_equal.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_equal.c,v retrieving revision 1.1 diff -u -r1.1 thr_equal.c --- thread/thr_equal.c 1 Apr 2003 03:46:28 -0000 1.1 +++ thread/thr_equal.c 28 Mar 2006 18:12:41 -0000 @@ -31,7 +31,11 @@ * * $FreeBSD: src/lib/libthr/thread/thr_equal.c,v 1.1 2003/04/01 03:46:28 jeff Exp $ */ + +#include "namespace.h" #include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_equal, pthread_equal); Index: thread/thr_exit.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_exit.c,v retrieving revision 1.20 diff -u -r1.20 thr_exit.c --- thread/thr_exit.c 5 Jan 2006 13:51:22 -0000 1.20 +++ thread/thr_exit.c 28 Mar 2006 18:12:41 -0000 @@ -32,10 +32,15 @@ * $FreeBSD: src/lib/libthr/thread/thr_exit.c,v 1.20 2006/01/05 13:51:22 davidxu Exp $ */ +#include "namespace.h" +#include +#include +#include #include +#include #include #include -#include +#include "un-namespace.h" #include "thr_private.h" @@ -44,7 +49,7 @@ __weak_reference(_pthread_exit, pthread_exit); void -_thread_exit(char *fname, int lineno, char *msg) +_thread_exit(const char *fname, int lineno, const char *msg) { /* Write an error message to the standard error file descriptor: */ @@ -103,7 +108,7 @@ /* Save the return value: */ curthread->ret = status; while (curthread->cleanup != NULL) { - pthread_cleanup_pop(1); + _pthread_cleanup_pop(1); } if (curthread->attr.cleanup_attr != NULL) { curthread->attr.cleanup_attr(curthread->attr.arg_attr); Index: thread/thr_fork.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_fork.c,v retrieving revision 1.3 diff -u -r1.3 thr_fork.c --- thread/thr_fork.c 12 Jan 2006 07:28:21 -0000 1.3 +++ thread/thr_fork.c 28 Mar 2006 18:12:41 -0000 @@ -60,12 +60,17 @@ * */ +#include "namespace.h" +#include +#include +#include #include -#include -#include -#include #include #include +#include +#include +#include +#include "un-namespace.h" #include "libc_private.h" #include "thr_private.h" @@ -94,6 +99,8 @@ return (0); } +pid_t _fork(void); + __weak_reference(_fork, fork); pid_t Index: thread/thr_getprio.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_getprio.c,v retrieving revision 1.1 diff -u -r1.1 thr_getprio.c --- thread/thr_getprio.c 1 Apr 2003 03:46:28 -0000 1.1 +++ thread/thr_getprio.c 28 Mar 2006 18:12:41 -0000 @@ -31,8 +31,12 @@ * * $FreeBSD: src/lib/libthr/thread/thr_getprio.c,v 1.1 2003/04/01 03:46:28 jeff Exp $ */ + +#include "namespace.h" #include #include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_getprio, pthread_getprio); @@ -43,7 +47,7 @@ int policy, ret; struct sched_param param; - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) + if ((ret = _pthread_getschedparam(pthread, &policy, ¶m)) == 0) ret = param.sched_priority; else { /* Invalid thread: */ Index: thread/thr_getschedparam.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_getschedparam.c,v retrieving revision 1.3 diff -u -r1.3 thr_getschedparam.c --- thread/thr_getschedparam.c 2 Apr 2005 01:20:00 -0000 1.3 +++ thread/thr_getschedparam.c 28 Mar 2006 18:12:41 -0000 @@ -32,15 +32,17 @@ * $FreeBSD: src/lib/libthr/thread/thr_getschedparam.c,v 1.3 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "thr_private.h" __weak_reference(_pthread_getschedparam, pthread_getschedparam); int -_pthread_getschedparam(pthread_t pthread, int *policy, +_pthread_getschedparam(pthread_t pthread, int *policy, struct sched_param *param) { struct pthread *curthread = _get_curthread(); Index: thread/thr_info.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_info.c,v retrieving revision 1.7 diff -u -r1.7 thr_info.c --- thread/thr_info.c 5 Feb 2006 02:26:17 -0000 1.7 +++ thread/thr_info.c 28 Mar 2006 18:12:41 -0000 @@ -32,9 +32,15 @@ * $FreeBSD: src/lib/libthr/thread/thr_info.c,v 1.7 2006/02/05 02:26:17 davidxu Exp $ */ +#include "namespace.h" +#include +#include +#include +#include #include #include #include +#include "un-namespace.h" #include "thr_private.h" @@ -42,7 +48,7 @@ /* Set the thread name for debug. */ void -_pthread_set_name_np(pthread_t thread, char *name) +_pthread_set_name_np(pthread_t thread, const char *name) { struct pthread *curthread = _get_curthread(); int ret = 0; Index: thread/thr_init.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_init.c,v retrieving revision 1.32 diff -u -r1.32 thr_init.c --- thread/thr_init.c 27 Mar 2006 23:50:21 -0000 1.32 +++ thread/thr_init.c 28 Mar 2006 18:41:34 -0000 @@ -35,11 +35,13 @@ #include "namespace.h" #include -#include #include +#include +#include #include #include -#include +#include +#include #include #include #include @@ -95,10 +97,10 @@ }; pid_t _thr_pid; -int _thr_guard_default; -int _thr_stack_default = THR_STACK_DEFAULT; -int _thr_stack_initial = THR_STACK_INITIAL; -int _thr_page_size; +size_t _thr_guard_default; +size_t _thr_stack_default = THR_STACK_DEFAULT; +size_t _thr_stack_initial = THR_STACK_INITIAL; +size_t _thr_page_size; int _gc_count; umtx_t _mutex_static_lock; umtx_t _cond_static_lock; @@ -389,9 +391,8 @@ * resource limits, so this stack needs an explicitly mapped * red zone to protect the thread stack that is just beyond. */ - if (mmap((void *)_usrstack - _thr_stack_initial - - _thr_guard_default, _thr_guard_default, 0, MAP_ANON, - -1, 0) == MAP_FAILED) + if (mmap((char *)_usrstack - _thr_stack_initial - _thr_guard_default, + _thr_guard_default, 0, MAP_ANON, -1, 0) == MAP_FAILED) PANIC("Cannot allocate red zone for initial thread"); /* @@ -403,7 +404,7 @@ * actually free() it; it just puts it in the free * stack queue for later reuse. */ - thread->attr.stackaddr_attr = (void *)_usrstack - _thr_stack_initial; + thread->attr.stackaddr_attr = (char *)_usrstack - _thr_stack_initial; thread->attr.stacksize_attr = _thr_stack_initial; thread->attr.guardsize_attr = _thr_guard_default; thread->attr.flags |= THR_STACK_USER; Index: thread/thr_join.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_join.c,v retrieving revision 1.20 diff -u -r1.20 thr_join.c --- thread/thr_join.c 19 Dec 2005 03:20:55 -0000 1.20 +++ thread/thr_join.c 28 Mar 2006 18:12:41 -0000 @@ -27,8 +27,11 @@ * */ +#include "namespace.h" #include #include +#include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_kern.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_kern.c,v retrieving revision 1.20 diff -u -r1.20 thr_kern.c --- thread/thr_kern.c 25 Mar 2006 04:49:07 -0000 1.20 +++ thread/thr_kern.c 28 Mar 2006 18:12:41 -0000 @@ -27,9 +27,14 @@ * $FreeBSD: src/lib/libthr/thread/thr_kern.c,v 1.20 2006/03/25 04:49:07 davidxu Exp $ */ +#include "namespace.h" #include #include +#include +#include #include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -63,7 +68,7 @@ _thr_signal_block(struct pthread *curthread) { sigset_t set; - + if (curthread->sigblock > 0) { curthread->sigblock++; return; Index: thread/thr_kill.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_kill.c,v retrieving revision 1.1 diff -u -r1.1 thr_kill.c --- thread/thr_kill.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_kill.c 28 Mar 2006 18:12:41 -0000 @@ -32,9 +32,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_kill.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" +#include +#include #include #include #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_list.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_list.c,v retrieving revision 1.7 diff -u -r1.7 thr_list.c --- thread/thr_list.c 24 Mar 2006 04:34:06 -0000 1.7 +++ thread/thr_list.c 28 Mar 2006 18:12:41 -0000 @@ -27,15 +27,16 @@ * $FreeBSD: src/lib/libthr/thread/thr_list.c,v 1.7 2006/03/24 04:34:06 davidxu Exp $ */ +#include "namespace.h" #include #include - +#include #include #include -#include +#include "un-namespace.h" -#include "thr_private.h" #include "libc_private.h" +#include "thr_private.h" /*#define DEBUG_THREAD_LIST */ #ifdef DEBUG_THREAD_LIST @@ -217,8 +218,10 @@ } static void -thr_destroy(struct pthread *curthread __unused, struct pthread *thread) +thr_destroy(struct pthread *curthread, struct pthread *thread) { + (void)curthread; + free(thread); } @@ -312,6 +315,8 @@ void _thr_ref_delete_unlocked(struct pthread *curthread, struct pthread *thread) { + (void)curthread; + if (thread != NULL) { thread->refcount--; if ((thread->refcount == 0) && thread->state == PS_DEAD && @@ -326,6 +331,8 @@ { struct pthread *pthread; + (void)curthread; + if (thread == NULL) /* Invalid thread: */ return (EINVAL); @@ -334,7 +341,7 @@ if (pthread) { if (include_dead == 0 && pthread->state == PS_DEAD) { pthread = NULL; - } + } } /* Return zero if the thread exists: */ Index: thread/thr_main_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_main_np.c,v retrieving revision 1.2 diff -u -r1.2 thr_main_np.c --- thread/thr_main_np.c 2 Apr 2005 01:20:00 -0000 1.2 +++ thread/thr_main_np.c 28 Mar 2006 18:12:41 -0000 @@ -27,8 +27,10 @@ * $FreeBSD: src/lib/libthr/thread/thr_main_np.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "thr_private.h" @@ -44,5 +46,5 @@ if (!_thr_initial) return (-1); else - return (pthread_equal(pthread_self(), _thr_initial) ? 1 : 0); + return (_pthread_equal(_pthread_self(), _thr_initial) ? 1 : 0); } Index: thread/thr_multi_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_multi_np.c,v retrieving revision 1.1 diff -u -r1.1 thr_multi_np.c --- thread/thr_multi_np.c 1 Apr 2003 03:46:29 -0000 1.1 +++ thread/thr_multi_np.c 28 Mar 2006 18:12:41 -0000 @@ -31,8 +31,13 @@ * * $FreeBSD: src/lib/libthr/thread/thr_multi_np.c,v 1.1 2003/04/01 03:46:29 jeff Exp $ */ + +#include "namespace.h" #include #include +#include "un-namespace.h" + +#include "thr_private.h" __weak_reference(_pthread_multi_np, pthread_multi_np); @@ -45,6 +50,6 @@ * XXX - Do we want to do this? * __is_threaded = 1; */ - pthread_resume_all_np(); + _pthread_resume_all_np(); return (0); } Index: thread/thr_mutex.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_mutex.c,v retrieving revision 1.40 diff -u -r1.40 thr_mutex.c --- thread/thr_mutex.c 27 Mar 2006 23:50:21 -0000 1.40 +++ thread/thr_mutex.c 28 Mar 2006 18:12:42 -0000 @@ -33,12 +33,15 @@ * $FreeBSD: src/lib/libthr/thread/thr_mutex.c,v 1.40 2006/03/27 23:50:21 davidxu Exp $ */ -#include -#include -#include +#include "namespace.h" #include #include +#include #include +#include +#include +#include "un-namespace.h" + #include "thr_private.h" #if defined(_PTHREADS_INVARIANTS) @@ -69,6 +72,11 @@ const struct timespec *abstime); static int mutex_unlock_common(pthread_mutex_t *, int); +int __pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); +int __pthread_mutex_lock(pthread_mutex_t *); +int __pthread_mutex_timedlock(pthread_mutex_t *, const struct timespec *); +int __pthread_mutex_trylock(pthread_mutex_t *); + __weak_reference(__pthread_mutex_init, pthread_mutex_init); __weak_reference(__pthread_mutex_lock, pthread_mutex_lock); __weak_reference(__pthread_mutex_timedlock, pthread_mutex_timedlock); @@ -465,10 +473,12 @@ { int ret; + (void)curthread; + switch (m->m_type) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_NORMAL: - ret = EBUSY; + ret = EBUSY; break; case PTHREAD_MUTEX_RECURSIVE: @@ -490,10 +500,12 @@ static int mutex_self_lock(struct pthread *curthread, pthread_mutex_t m, - const struct timespec *abstime) + const struct timespec *abstime) { struct timespec ts1, ts2; - int ret; + int ret; + + (void)curthread; switch (m->m_type) { case PTHREAD_MUTEX_ERRORCHECK: @@ -507,7 +519,7 @@ * POSIX specifies that mutexes should return * EDEADLK if a recursive lock is detected. */ - ret = EDEADLK; + ret = EDEADLK; } break; @@ -599,10 +611,12 @@ int _pthread_mutex_getprioceiling(pthread_mutex_t *mutex, - int *prioceiling) + int *prioceiling) { int ret; + (void)prioceiling; + if (*mutex == NULL) ret = EINVAL; else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) @@ -615,7 +629,7 @@ int _pthread_mutex_setprioceiling(pthread_mutex_t *mutex, - int prioceiling, int *old_ceiling) + int prioceiling, int *old_ceiling) { int ret = 0; int tmp; @@ -624,10 +638,10 @@ ret = EINVAL; else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT) ret = EINVAL; - else if ((ret = pthread_mutex_lock(mutex)) == 0) { + else if ((ret = _pthread_mutex_lock(mutex)) == 0) { tmp = (*mutex)->m_prio; (*mutex)->m_prio = prioceiling; - ret = pthread_mutex_unlock(mutex); + ret = _pthread_mutex_unlock(mutex); /* Return the old ceiling. */ *old_ceiling = tmp; Index: thread/thr_mutex_prioceiling.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_mutex_prioceiling.c,v retrieving revision 1.4 diff -u -r1.4 thr_mutex_prioceiling.c --- thread/thr_mutex_prioceiling.c 2 Apr 2005 01:20:00 -0000 1.4 +++ thread/thr_mutex_prioceiling.c 28 Mar 2006 18:12:42 -0000 @@ -32,10 +32,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_mutex_prioceiling.c,v 1.4 2005/04/02 01:20:00 davidxu Exp $ */ -#include -#include +#include "namespace.h" #include #include +#include +#include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling); Index: thread/thr_mutex_protocol.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_mutex_protocol.c,v retrieving revision 1.3 diff -u -r1.3 thr_mutex_protocol.c --- thread/thr_mutex_protocol.c 2 Apr 2005 01:20:00 -0000 1.3 +++ thread/thr_mutex_protocol.c 28 Mar 2006 18:12:42 -0000 @@ -32,10 +32,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_mutex_protocol.c,v 1.3 2005/04/02 01:20:00 davidxu Exp $ */ -#include -#include +#include "namespace.h" #include #include +#include +#include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol); Index: thread/thr_mutexattr.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_mutexattr.c,v retrieving revision 1.4 diff -u -r1.4 thr_mutexattr.c --- thread/thr_mutexattr.c 27 Mar 2006 23:50:21 -0000 1.4 +++ thread/thr_mutexattr.c 28 Mar 2006 18:12:42 -0000 @@ -65,10 +65,14 @@ * */ -#include -#include +#include "namespace.h" #include #include +#include +#include +#include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_mutexattr_init, pthread_mutexattr_init); @@ -90,12 +94,10 @@ int ret; pthread_mutexattr_t pattr; - if ((pattr = (pthread_mutexattr_t) - malloc(sizeof(struct pthread_mutex_attr))) == NULL) { + if ((pattr = malloc(sizeof(*pattr))) == NULL) { ret = ENOMEM; } else { - memcpy(pattr, &_pthread_mutexattr_default, - sizeof(struct pthread_mutex_attr)); + memcpy(pattr, &_pthread_mutexattr_default, sizeof(*pattr)); *attr = pattr; ret = 0; } Index: thread/thr_printf.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_printf.c,v retrieving revision 1.5 diff -u -r1.5 thr_printf.c --- thread/thr_printf.c 2 Apr 2005 01:20:00 -0000 1.5 +++ thread/thr_printf.c 28 Mar 2006 18:12:42 -0000 @@ -26,10 +26,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_printf.c,v 1.5 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" +#include #include #include #include -#include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_private.h =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_private.h,v retrieving revision 1.59 diff -u -r1.59 thr_private.h --- thread/thr_private.h 27 Mar 2006 23:50:21 -0000 1.59 +++ thread/thr_private.h 28 Mar 2006 18:41:51 -0000 @@ -32,29 +32,12 @@ #ifndef _THR_PRIVATE_H #define _THR_PRIVATE_H -/* - * Include files. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #ifndef __hidden #define __hidden __attribute__((visibility("hidden"))) #endif +#include + #include "pthread_md.h" #include "thr_umtx.h" #include "thread_db.h" @@ -68,11 +51,15 @@ /* * Kernel fatal error handler macro. */ -#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) +#define PANIC(string) _thread_exit(__FILE__, __LINE__, string) /* Output debug messages like this: */ -#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) -#define stderr_debug(args...) _thread_printf(STDOUT_FILENO, ##args) +#ifdef STDOUT_FILENO +#define stdout_debug(...) _thread_printf(STDOUT_FILENO, __VA_ARGS__) +#endif +#ifdef STDERR_FILENO +#define stderr_debug(...) _thread_printf(STDERR_FILENO, __VA_ARGS__) +#endif #ifdef _PTHREADS_INVARIANTS #define THR_ASSERT(cond, msg) do { \ @@ -203,7 +190,7 @@ */ struct pthread_cleanup { struct pthread_cleanup *next; - void (*routine)(); + void (*routine)(void *); void *routine_arg; int onstack; }; @@ -239,7 +226,7 @@ #define THR_STACK_USER 0x100 /* 0xFF reserved for */ int flags; void *arg_attr; - void (*cleanup_attr)(); + void (*cleanup_attr)(void *); void *stackaddr_attr; size_t stacksize_attr; size_t guardsize_attr; @@ -625,10 +612,10 @@ extern struct pthread_cond_attr _pthread_condattr_default __hidden; extern pid_t _thr_pid __hidden; -extern int _thr_guard_default __hidden; -extern int _thr_stack_default __hidden; -extern int _thr_stack_initial __hidden; -extern int _thr_page_size __hidden; +extern size_t _thr_guard_default __hidden; +extern size_t _thr_stack_default __hidden; +extern size_t _thr_stack_initial __hidden; +extern size_t _thr_page_size __hidden; /* Garbage thread count. */ extern int _gc_count __hidden; @@ -650,37 +637,11 @@ void _mutex_fork(struct pthread *curthread) __hidden; void _mutex_unlock_private(struct pthread *) __hidden; void _libpthread_init(struct pthread *) __hidden; -void *_pthread_getspecific(pthread_key_t); -int _pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); -int _pthread_cond_destroy(pthread_cond_t *); -int _pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); -int _pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, - const struct timespec *); -int _pthread_cond_signal(pthread_cond_t *); -int _pthread_cond_broadcast(pthread_cond_t *); int _pthread_create(pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine) (void *), void *arg); -int _pthread_key_create(pthread_key_t *, void (*) (void *)); -int _pthread_key_delete(pthread_key_t); -int _pthread_mutex_destroy(pthread_mutex_t *); -int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); -int _pthread_mutex_lock(pthread_mutex_t *); -int _pthread_mutex_trylock(pthread_mutex_t *); -int _pthread_mutex_unlock(pthread_mutex_t *); -int _pthread_mutexattr_init(pthread_mutexattr_t *); -int _pthread_mutexattr_destroy(pthread_mutexattr_t *); -int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); -int _pthread_once(pthread_once_t *, void (*) (void)); -int _pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *); -int _pthread_rwlock_destroy (pthread_rwlock_t *); -struct pthread *_pthread_self(void); -int _pthread_setspecific(pthread_key_t, const void *); -void _pthread_testcancel(void); void _pthread_yield(void); -void _pthread_cleanup_push(void (*routine) (void *), void *routine_arg); -void _pthread_cleanup_pop(int execute); struct pthread *_thr_alloc(struct pthread *) __hidden; -void _thread_exit(char *, int, char *) __hidden __dead2; +void _thread_exit(const char *, int, const char *) __hidden __dead2; void _thr_exit_cleanup(void) __hidden; int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; @@ -718,6 +679,7 @@ void _thr_report_death(struct pthread *curthread) __hidden; void _thread_bp_create(void); void _thread_bp_death(void); +void _thread_seterrno(pthread_t, int); /* #include */ #ifdef _SYS_AIO_H_ Index: thread/thr_pspinlock.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_pspinlock.c,v retrieving revision 1.1 diff -u -r1.1 thr_pspinlock.c --- thread/thr_pspinlock.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_pspinlock.c 28 Mar 2006 18:12:42 -0000 @@ -26,9 +26,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_pspinlock.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" + #include "thr_private.h" #define SPIN_COUNT 100000 Index: thread/thr_resume_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_resume_np.c,v retrieving revision 1.9 diff -u -r1.9 thr_resume_np.c --- thread/thr_resume_np.c 5 Jan 2006 13:51:22 -0000 1.9 +++ thread/thr_resume_np.c 28 Mar 2006 18:12:42 -0000 @@ -32,8 +32,11 @@ * $FreeBSD: src/lib/libthr/thread/thr_resume_np.c,v 1.9 2006/01/05 13:51:22 davidxu Exp $ */ +#include "namespace.h" #include #include +#include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_rtld.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_rtld.c,v retrieving revision 1.2 diff -u -r1.2 thr_rtld.c --- thread/thr_rtld.c 25 Mar 2006 05:14:21 -0000 1.2 +++ thread/thr_rtld.c 28 Mar 2006 18:13:54 -0000 @@ -30,8 +30,10 @@ /* * A lockless rwlock for rtld. */ -#include + +#include "namespace.h" #include +#include "un-namespace.h" #include "rtld_lock.h" #include "thr_private.h" @@ -167,6 +169,8 @@ static int _thr_rtld_set_flag(int mask) { + (void)mask; + /* * The caller's code in rtld-elf is broken, it is not signal safe, * just return zero to fool it. @@ -177,6 +181,8 @@ static int _thr_rtld_clr_flag(int mask) { + (void)mask; + return (0); } @@ -190,7 +196,7 @@ curthread = _get_curthread(); /* force to resolve _umtx_op PLT */ - _umtx_op((struct umtx *)&dummy, UMTX_OP_WAKE, 1, 0, 0); + _umtx_op((struct umtx *)(void *)&dummy, UMTX_OP_WAKE, 1, 0, 0); li.lock_create = _thr_rtld_lock_create; li.lock_destroy = _thr_rtld_lock_destroy; Index: thread/thr_rwlock.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_rwlock.c,v retrieving revision 1.8 diff -u -r1.8 thr_rwlock.c --- thread/thr_rwlock.c 2 Apr 2005 01:20:00 -0000 1.8 +++ thread/thr_rwlock.c 28 Mar 2006 18:12:42 -0000 @@ -26,13 +26,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_rwlock.c,v 1.8 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include -#include - -#include "namespace.h" #include +#include #include "un-namespace.h" + #include "thr_private.h" /* maximum number of times a read lock may be obtained */ @@ -58,6 +58,8 @@ pthread_rwlock_t prwlock; int ret; + (void)attr; + /* allocate rwlock object */ prwlock = (pthread_rwlock_t)malloc(sizeof(struct pthread_rwlock)); Index: thread/thr_rwlockattr.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_rwlockattr.c,v retrieving revision 1.1 diff -u -r1.1 thr_rwlockattr.c --- thread/thr_rwlockattr.c 1 Apr 2003 03:46:29 -0000 1.1 +++ thread/thr_rwlockattr.c 28 Mar 2006 18:12:42 -0000 @@ -26,10 +26,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_rwlockattr.c,v 1.1 2003/04/01 03:46:29 jeff Exp $ */ +#include "namespace.h" #include +#include #include +#include "un-namespace.h" -#include #include "thr_private.h" __weak_reference(_pthread_rwlockattr_destroy, pthread_rwlockattr_destroy); Index: thread/thr_self.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_self.c,v retrieving revision 1.3 diff -u -r1.3 thr_self.c --- thread/thr_self.c 2 Apr 2005 01:20:00 -0000 1.3 +++ thread/thr_self.c 28 Mar 2006 18:12:42 -0000 @@ -32,7 +32,9 @@ * $FreeBSD: src/lib/libthr/thread/thr_self.c,v 1.3 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_sem.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_sem.c,v retrieving revision 1.7 diff -u -r1.7 thr_sem.c --- thread/thr_sem.c 28 Mar 2006 21:46:55 -0000 1.7 +++ thread/thr_sem.c 29 Mar 2006 05:53:54 -0000 @@ -36,10 +36,10 @@ #include #include #include +#include <_semaphore.h> #include #include #include -#include <_semaphore.h> #include "un-namespace.h" #include "thr_private.h" @@ -76,7 +76,7 @@ return (NULL); } - sem = (sem_t)malloc(sizeof(struct sem)); + sem = malloc(sizeof(*sem)); if (sem == NULL) { errno = ENOSPC; return (NULL); Index: thread/thr_seterrno.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_seterrno.c,v retrieving revision 1.2 diff -u -r1.2 thr_seterrno.c --- thread/thr_seterrno.c 2 Apr 2005 01:20:00 -0000 1.2 +++ thread/thr_seterrno.c 28 Mar 2006 18:12:42 -0000 @@ -32,13 +32,15 @@ * $FreeBSD: src/lib/libthr/thread/thr_seterrno.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "thr_private.h" /* * This function needs to reference the global error variable which is - * normally hidden from the user. + * normally hidden from the user. */ #undef errno extern int errno; @@ -53,7 +55,7 @@ else /* * Threads other than the initial thread always use the error - * field in the thread structureL + * field in the thread structure */ thread->error = error; } Index: thread/thr_setprio.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_setprio.c,v retrieving revision 1.1 diff -u -r1.1 thr_setprio.c --- thread/thr_setprio.c 1 Apr 2003 03:46:29 -0000 1.1 +++ thread/thr_setprio.c 28 Mar 2006 18:14:25 -0000 @@ -31,7 +31,11 @@ * * $FreeBSD: src/lib/libthr/thread/thr_setprio.c,v 1.1 2003/04/01 03:46:29 jeff Exp $ */ + +#include "namespace.h" #include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_setprio, pthread_setprio); @@ -42,9 +46,9 @@ int ret, policy; struct sched_param param; - if ((ret = pthread_getschedparam(pthread, &policy, ¶m)) == 0) { + if ((ret = _pthread_getschedparam(pthread, &policy, ¶m)) == 0) { param.sched_priority = prio; - ret = pthread_setschedparam(pthread, policy, ¶m); + ret = _pthread_setschedparam(pthread, policy, ¶m); } /* Return the error status: */ Index: thread/thr_setschedparam.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_setschedparam.c,v retrieving revision 1.10 diff -u -r1.10 thr_setschedparam.c --- thread/thr_setschedparam.c 27 Mar 2006 23:50:21 -0000 1.10 +++ thread/thr_setschedparam.c 28 Mar 2006 18:12:42 -0000 @@ -32,9 +32,11 @@ * $FreeBSD: src/lib/libthr/thread/thr_setschedparam.c,v 1.10 2006/03/27 23:50:21 davidxu Exp $ */ -#include +#include "namespace.h" #include +#include #include +#include "un-namespace.h" #include "thr_private.h" @@ -45,7 +47,7 @@ * in kernel, doing it in userland is no-op. */ int -_pthread_setschedparam(pthread_t pthread, int policy, +_pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param) { struct pthread *curthread = _get_curthread(); Index: thread/thr_sig.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_sig.c,v retrieving revision 1.17 diff -u -r1.17 thr_sig.c --- thread/thr_sig.c 26 Mar 2006 01:57:03 -0000 1.17 +++ thread/thr_sig.c 28 Mar 2006 18:40:17 -0000 @@ -26,15 +26,17 @@ * $FreeBSD: src/lib/libthr/thread/thr_sig.c,v 1.17 2006/03/26 01:57:03 davidxu Exp $ */ +#include "namespace.h" #include -#include #include -#include +#include #include #include -#include -#include #include +#include +#include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -205,6 +207,11 @@ return (ret); } +int __sigwait(const sigset_t *, int *); +int __sigtimedwait(const sigset_t *, siginfo_t *, + const struct timespec *); +int __sigwaitinfo(const sigset_t *, siginfo_t *); + __weak_reference(__sigwait, sigwait); __weak_reference(__sigtimedwait, sigtimedwait); __weak_reference(__sigwaitinfo, sigwaitinfo); Index: thread/thr_sigmask.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_sigmask.c,v retrieving revision 1.1 diff -u -r1.1 thr_sigmask.c --- thread/thr_sigmask.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_sigmask.c 28 Mar 2006 18:12:42 -0000 @@ -32,9 +32,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_sigmask.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_sigmask, pthread_sigmask); Index: thread/thr_single_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_single_np.c,v retrieving revision 1.1 diff -u -r1.1 thr_single_np.c --- thread/thr_single_np.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_single_np.c 28 Mar 2006 18:16:18 -0000 @@ -32,8 +32,10 @@ * $FreeBSD: src/lib/libthr/thread/thr_single_np.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" __weak_reference(_pthread_single_np, pthread_single_np); @@ -41,7 +43,7 @@ { /* Enter single-threaded (non-POSIX) scheduling mode: */ - pthread_suspend_all_np(); + _pthread_suspend_all_np(); /* * XXX - Do we want to do this? * __is_threaded = 0; Index: thread/thr_spec.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_spec.c,v retrieving revision 1.3 diff -u -r1.3 thr_spec.c --- thread/thr_spec.c 2 Apr 2005 01:20:00 -0000 1.3 +++ thread/thr_spec.c 28 Mar 2006 18:19:36 -0000 @@ -32,11 +32,16 @@ * $FreeBSD: src/lib/libthr/thread/thr_spec.c,v 1.3 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" +#include +#include +#include +#include #include #include #include -#include -#include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -98,7 +103,7 @@ return (ret); } -void +void _thread_cleanupspecific(void) { struct pthread *curthread = _get_curthread(); @@ -168,7 +173,7 @@ return (new_data); } -int +int _pthread_setspecific(pthread_key_t key, const void *value) { struct pthread *pthread; @@ -218,7 +223,7 @@ } else { /* * This key has not been used before, so return NULL - * instead: + * instead: */ data = NULL; } Index: thread/thr_spinlock.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_spinlock.c,v retrieving revision 1.12 diff -u -r1.12 thr_spinlock.c --- thread/thr_spinlock.c 13 Jan 2006 06:14:04 -0000 1.12 +++ thread/thr_spinlock.c 28 Mar 2006 18:19:50 -0000 @@ -33,10 +33,11 @@ * */ +#include "namespace.h" #include -#include -#include #include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -83,6 +84,8 @@ void _spinlock_debug(spinlock_t *lck, char *fname, int lineno) { + (void)fname; + (void)lineno; _spinlock(lck); } Index: thread/thr_stack.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_stack.c,v retrieving revision 1.6 diff -u -r1.6 thr_stack.c --- thread/thr_stack.c 2 Apr 2005 01:20:00 -0000 1.6 +++ thread/thr_stack.c 28 Mar 2006 18:43:35 -0000 @@ -27,11 +27,13 @@ * $FreeBSD: src/lib/libthr/thread/thr_stack.c,v 1.6 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" #include "thr_private.h" @@ -189,11 +191,11 @@ else { /* Allocate a stack from usrstack. */ if (last_stack == NULL) - last_stack = _usrstack - _thr_stack_initial - + last_stack = (char *)_usrstack - _thr_stack_initial - _thr_guard_default; /* Allocate a new stack. */ - stackaddr = last_stack - stacksize - guardsize; + stackaddr = (char *)last_stack - stacksize - guardsize; /* * Even if stack allocation fails, we don't want to try to @@ -202,7 +204,7 @@ * likely reason for an mmap() error is a stack overflow of * the adjacent thread stack. */ - last_stack -= (stacksize + guardsize); + last_stack = (char *)last_stack - (stacksize + guardsize); /* Release the lock before mmap'ing it. */ THREAD_LIST_UNLOCK(curthread); @@ -236,8 +238,8 @@ if ((attr != NULL) && ((attr->flags & THR_STACK_USER) == 0) && (attr->stackaddr_attr != NULL)) { - spare_stack = (attr->stackaddr_attr + attr->stacksize_attr - - sizeof(struct stack)); + spare_stack = (struct stack *)((char *)attr->stackaddr_attr + + attr->stacksize_attr - sizeof(struct stack)); spare_stack->stacksize = round_up(attr->stacksize_attr); spare_stack->guardsize = round_up(attr->guardsize_attr); spare_stack->stackaddr = attr->stackaddr_attr; Index: thread/thr_suspend_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_suspend_np.c,v retrieving revision 1.6 diff -u -r1.6 thr_suspend_np.c --- thread/thr_suspend_np.c 20 Feb 2006 09:02:40 -0000 1.6 +++ thread/thr_suspend_np.c 28 Mar 2006 18:28:48 -0000 @@ -32,8 +32,14 @@ * $FreeBSD: src/lib/libthr/thread/thr_suspend_np.c,v 1.6 2006/02/20 09:02:40 davidxu Exp $ */ +#include "namespace.h" +#include +#include +#include #include #include +#include +#include "un-namespace.h" #include "thr_private.h" @@ -55,8 +61,7 @@ ret = EDEADLK; /* Add a reference to the thread: */ - else if ((ret = _thr_ref_add(curthread, thread, /*include dead*/0)) - == 0) { + else if ((ret = _thr_ref_add(curthread, thread, 0)) == 0) { /* Lock the threads scheduling queue: */ THR_THREAD_LOCK(curthread, thread); suspend_common(curthread, thread, 1); Index: thread/thr_switch_np.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_switch_np.c,v retrieving revision 1.1 diff -u -r1.1 thr_switch_np.c --- thread/thr_switch_np.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_switch_np.c 28 Mar 2006 18:12:42 -0000 @@ -32,9 +32,11 @@ * $FreeBSD: src/lib/libthr/thread/thr_switch_np.c,v 1.1 2005/04/02 01:20:00 davidxu Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "thr_private.h" @@ -45,11 +47,13 @@ int _pthread_switch_add_np(pthread_switch_routine_t routine) { + (void)routine; return (ENOTSUP); } int _pthread_switch_delete_np(pthread_switch_routine_t routine) { + (void)routine; return (ENOTSUP); } Index: thread/thr_symbols.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_symbols.c,v retrieving revision 1.3 diff -u -r1.3 thr_symbols.c --- thread/thr_symbols.c 1 Sep 2005 15:21:23 -0000 1.3 +++ thread/thr_symbols.c 28 Mar 2006 18:12:42 -0000 @@ -32,10 +32,12 @@ * $FreeBSD: src/lib/libthr/thread/thr_symbols.c,v 1.3 2005/09/01 15:21:23 stefanf Exp $ */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_syscalls.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_syscalls.c,v retrieving revision 1.12 diff -u -r1.12 thr_syscalls.c --- thread/thr_syscalls.c 2 Nov 2005 14:06:29 -0000 1.12 +++ thread/thr_syscalls.c 28 Mar 2006 18:21:30 -0000 @@ -64,6 +64,7 @@ * */ +#include "namespace.h" #include #include #include @@ -72,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +89,7 @@ #include #include #include +#include "un-namespace.h" #include "thr_private.h" Index: thread/thr_umtx.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_umtx.c,v retrieving revision 1.1 diff -u -r1.1 thr_umtx.c --- thread/thr_umtx.c 2 Apr 2005 01:20:00 -0000 1.1 +++ thread/thr_umtx.c 28 Mar 2006 18:12:42 -0000 @@ -43,10 +43,10 @@ const struct timespec *timeout) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && - timeout->tv_nsec <= 0))) + timeout->tv_nsec <= 0))) return (ETIMEDOUT); if (_umtx_op((struct umtx *)mtx, UMTX_OP_LOCK, id, 0, - (void *)timeout) == 0) + __DECONST(void *, timeout)) == 0) return (0); return (errno); } @@ -63,10 +63,9 @@ _thr_umtx_wait(volatile umtx_t *mtx, long id, const struct timespec *timeout) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && - timeout->tv_nsec <= 0))) + timeout->tv_nsec <= 0))) return (ETIMEDOUT); - if (_umtx_op((struct umtx *)mtx, UMTX_OP_WAIT, id, 0, - (void*) timeout) == 0) + if (_umtx_op((struct umtx *)mtx, UMTX_OP_WAIT, id, 0, __DECONST(void *, timeout)) == 0) return (0); return (errno); } Index: thread/thr_umtx.h =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_umtx.h,v retrieving revision 1.3 diff -u -r1.3 thr_umtx.h --- thread/thr_umtx.h 21 Dec 2005 03:53:29 -0000 1.3 +++ thread/thr_umtx.h 28 Mar 2006 18:12:42 -0000 @@ -29,6 +29,9 @@ #ifndef _THR_FBSD_UMTX_H_ #define _THR_FBSD_UMTX_H_ +#include +#include +#include #include typedef long umtx_t; Index: thread/thr_yield.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_yield.c,v retrieving revision 1.1 diff -u -r1.1 thr_yield.c --- thread/thr_yield.c 1 Apr 2003 03:46:29 -0000 1.1 +++ thread/thr_yield.c 28 Mar 2006 18:12:42 -0000 @@ -31,7 +31,11 @@ * * $FreeBSD: src/lib/libthr/thread/thr_yield.c,v 1.1 2003/04/01 03:46:29 jeff Exp $ */ + +#include "namespace.h" #include +#include "un-namespace.h" + #include "thr_private.h" __weak_reference(_pthread_yield, pthread_yield); --=-=-=-- From owner-freebsd-threads@FreeBSD.ORG Wed Mar 29 08:33:42 2006 Return-Path: X-Original-To: threads@freebsd.org 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 35E1916A41F; Wed, 29 Mar 2006 08:33:42 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E0B1943D48; Wed, 29 Mar 2006 08:33:41 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from [127.0.0.1] (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2T8XcRK064708; Wed, 29 Mar 2006 08:33:39 GMT (envelope-from davidxu@freebsd.org) Message-ID: <442A466A.9040506@freebsd.org> Date: Wed, 29 Mar 2006 16:33:46 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20060302 X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Dag-Erling_Sm=F8rgrav?= References: <86slp1u4qb.fsf@xps.des.no> In-Reply-To: <86slp1u4qb.fsf@xps.des.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: threads@freebsd.org, jeff@freebsd.org Subject: Re: libthr cleanup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2006 08:33:42 -0000 Dag-Erling Smørgrav wrote: > The attached patch brings libthr up to WARNS level 2. There is also a > small amount of style and whitespace changes mixed in, mostly because > I'm so conditioned to style(9) that my fingers sometimes do these > things automatically. > I have bunch of patches in hand which compiles at level 3, if you commit it, there will lots of conflict to my working copy. > Parts of the patch go a little further than level 2, but we're nowhere > near level 3 (or antything higher). The major obstacle is the umtx > interface, which in my eyes is fundamentally broken. > The _umtx_op() syscall is intended to replace _umtx_lock() and > _umtx_unlock(), and support other operations like sleep, wakeup etc. > > This is the wrong way to go. If we applied this kind of thinking > universally, we'd just define all our system calls as macro wrappers > for __syscall(). > > Beyond these purely philosophical aspects, _umtx_op() seems designed > to encourage poor coding practices. It's impossible to use in a type- > safe manner: its first argument is supposed to be a struct umtx *, but > I don't think there's a single instance in libthr where it is called > with an actual struct umtx *. Instead, libthr uses umtx_t, which is > defined as long. Sometimes, an umtx_t is passed as the third argument > to _umtx_op() as well. Various fields in struct pthread, struct > pthread_barrier and struct pthread_cond are declared as umtx_t. Some > are used purely as cookies for passing to _umtx_op(); some are used as > counters or state variables. > > It's a miracle libthr works at all. The kernel expects a pointer to a > struct umtx; instead, it gets (mostly) a pointer to long. Luckily, > struct umtx (which contains a single pointer) is the same size as long > on all our platforms. > > _umtx_op() needs to be split into four system calls: > > int _umtx_lock_timeout(struct umtx *mtx, > const struct timespec * __restrict timeout); > int _umtx_unlock(struct umtx *mtx); > int _umtx_wait_timeout(const void *cookie, struct umtx *mtx, > const struct timespec * __restrict timeout); > int _umtx_wake(const void *cookie); > > _umtx_unlock() already exists with the correct semantics; the rest are > new. Note that we can't just add a struct timespec to _umtx_lock(), > as that would break the upgrade path from RELENG_5; hence the _timeout > suffix. > When libthr was redesigned, things were not clear, I have figured out all semantics needed to implement libthr, the above functions are the interfaces current internally implemented by libthr, and functions in umtx.h is not used because it can generate bloat code than the versions in libthr, current libthr shared library only has 64K size. I really dont need struct umtx at all, an integer is enough, basic idea is using atomic operations to test in userland and wait in kernel. the above functions should be changed to: int _umtx_lock_timeout(umtx_t *, const struct timespec * __restrict timeout); int _umtx_unlock(umtx_t *mtx); int _umtx_wait_timeout(umtx_t *, umtx_t expect, const struct timespec * __restrict timeout); int _umtx_wake(umtx_t *i, int number); the umtx_t could be an integer type, but to maintain binary compatibility, it has to be a long integer type. > I'm not sure the current implementation of UMTX_OP_WAIT / UMTX_OP_WAKE > in the kernel is correct. Normally, a wait primitive (like msleep(), > pthread_cond_wait() etc.) takes a cookie and a mutex, and unlocks the > mutex while it's sleeping on the cookie. It looks like the umtx code > originally worked like this, but I'm not sure it does anymore; it's > hard to unravel, partly because I haven't quite figured out the queues > yet and partly because I haven't had breakfast. > > DES > Well, I am not sure you know the history of umtx, the orignal work only did a lock and unlock semantic, there is no general sleep and wait semantic, orignal umtx code has obscure race, I think in early days, valgrind suffered from this bug. I am not sure you understand how a userland synchronization works, these two operations are used to implement compare and wait for a integer to be changed, you should check source code before talking a lot, saying that you doubt the UMTX_OP_WAIT and UMTX_OP_WAKE's correctness is not professional, there are users using libthr in daily work and stress testing had been done. I have put lots of work and time on libthr, I know the problems, though the _umtx interface is a bit ulgly because it was unclear when it was being designed, but I don't think it really hurt you or other people, it can be fixed in few days, I just was hesitating to add the new interfaces. David Xu From owner-freebsd-threads@FreeBSD.ORG Wed Mar 29 09:10:37 2006 Return-Path: X-Original-To: threads@freebsd.org 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 7A6B016A41F; Wed, 29 Mar 2006 09:10:37 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id F316E43D68; Wed, 29 Mar 2006 09:10:36 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id BCE1A2096; Wed, 29 Mar 2006 11:10:28 +0200 (CEST) X-Spam-Tests: AWL,BAYES_00,FORGED_RCVD_HELO X-Spam-Learn: ham X-Spam-Score: -2.4/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on tim.des.no Received: from xps.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id 1B4BD2081; Wed, 29 Mar 2006 11:10:28 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id E684B33C8D; Wed, 29 Mar 2006 11:10:27 +0200 (CEST) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: David Xu References: <86slp1u4qb.fsf@xps.des.no> <442A466A.9040506@freebsd.org> Date: Wed, 29 Mar 2006 11:10:27 +0200 In-Reply-To: <442A466A.9040506@freebsd.org> (David Xu's message of "Wed, 29 Mar 2006 16:33:46 +0800") Message-ID: <861wwlehvg.fsf@xps.des.no> User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: threads@freebsd.org, jeff@freebsd.org Subject: Re: libthr cleanup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2006 09:10:37 -0000 David Xu writes: > When libthr was redesigned, things were not clear, I have figured out > all semantics needed to implement libthr, the above functions are the > interfaces current internally implemented by libthr, and functions in > umtx.h is not used because it can generate bloat code than the > versions in libthr, current libthr shared library only has 64K size. > I really dont need struct umtx at all, an integer is enough, basic idea > is using atomic operations to test in userland and wait in kernel. > the above functions should be changed to: > int _umtx_lock_timeout(umtx_t *, > const struct timespec * __restrict timeout); > int _umtx_unlock(umtx_t *mtx); > int _umtx_wait_timeout(umtx_t *, umtx_t expect, > const struct timespec * __restrict timeout); > int _umtx_wake(umtx_t *i, int number); > > the umtx_t could be an integer type, but to maintain binary > compatibility, it has to be a long integer type. To maintain compatibility and ensure type safety, it should be a struct umtx. In effect, the wait / wake operations implement a condition variable. You should not use the same struct (or type) to describe the condition variable as the one you use to describe a mutex. Condition variables are always used in conjunction with a mutex. The mutex must be passed to the wait function so it can be unlocked while the waiting thread waits. It must be held by the thread calling the wake method. Neither the existing interface nor the one you propose do this. > Well, I am not sure you know the history of umtx, the orignal work > only did a lock and unlock semantic, there is no general sleep and > wait semantic, orignal umtx code has obscure race, I think in early > days, valgrind suffered from this bug. I am not sure you understand > how a userland synchronization works, these two operations are used > to implement compare and wait for a integer to be changed, You cannot "wait for an integer to be changed" (at least not without using hardware debugging facilities), and that is not what UMTX_OP_WAIT does. It is a botched condition variable. It waits for another thread to perform an UMTX_OP_WAKE operation with the correct arguments; the fact that an integer has changed is incidental, and the test for that change could be implemented in userland: look up condition variables in any good CS textbook and you will see an example of this, likely in the guise of a sample message queue (or mailbox) implementation. I can understand wanting to move the check into the kernel to avoid spurious context switches, but it has to be done right. > you > should check source code before talking a lot, That is precisely what I have done. > saying that you doubt > the UMTX_OP_WAIT and UMTX_OP_WAKE's correctness is not professional, > there are users using libthr in daily work and stress testing had > been done. > I have put lots of work and time on libthr, I know the problems, > though the _umtx interface is a bit ulgly because it was unclear > when it was being designed, but I don't think it really hurt you or > other people, it can be fixed in few days, I just was hesitating to > add the new interfaces. The amount of work you have put into libthr and its importance to your self-esteem do not guarantee its correctness. What is unprofessional here is 1) the quality of your code and 2) your refusal to consider that I might have a point. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no From owner-freebsd-threads@FreeBSD.ORG Wed Mar 29 09:39:50 2006 Return-Path: X-Original-To: threads@freebsd.org 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 6CA6516A422; Wed, 29 Mar 2006 09:39:50 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 18F2843D45; Wed, 29 Mar 2006 09:39:50 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from [127.0.0.1] (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2T9dk1O068079; Wed, 29 Mar 2006 09:39:48 GMT (envelope-from davidxu@freebsd.org) Message-ID: <442A55EB.9060009@freebsd.org> Date: Wed, 29 Mar 2006 17:39:55 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20060302 X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Dag-Erling_Sm=F8rgrav?= References: <86slp1u4qb.fsf@xps.des.no> <442A466A.9040506@freebsd.org> <861wwlehvg.fsf@xps.des.no> In-Reply-To: <861wwlehvg.fsf@xps.des.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: threads@freebsd.org, jeff@freebsd.org Subject: Re: libthr cleanup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2006 09:39:50 -0000 Dag-Erling Smørgrav wrote: > In effect, the wait / wake operations implement a condition variable. > You should not use the same struct (or type) to describe the condition > variable as the one you use to describe a mutex. > > Condition variables are always used in conjunction with a mutex. The > mutex must be passed to the wait function so it can be unlocked while > the waiting thread waits. It must be held by the thread calling the > wake method. Neither the existing interface nor the one you propose > do this. > You are talking about how to use it, not how to implement it. > You cannot "wait for an integer to be changed" (at least not without > using hardware debugging facilities), and that is not what > UMTX_OP_WAIT does. It is a botched condition variable. It waits for > another thread to perform an UMTX_OP_WAKE operation with the correct > arguments; the fact that an integer has changed is incidental, and the > test for that change could be implemented in userland: look up > condition variables in any good CS textbook and you will see an > example of this, likely in the guise of a sample message queue (or > mailbox) implementation. > again, there are many ways to implement it, I think you are talking about how to use it, not how to implement it. > I can understand wanting to move the check into the kernel to avoid > spurious context switches, but it has to be done right. > > >> you >>should check source code before talking a lot, > > > That is precisely what I have done. > > >> saying that you doubt >>the UMTX_OP_WAIT and UMTX_OP_WAKE's correctness is not professional, >>there are users using libthr in daily work and stress testing had >>been done. >>I have put lots of work and time on libthr, I know the problems, >>though the _umtx interface is a bit ulgly because it was unclear >>when it was being designed, but I don't think it really hurt you or >>other people, it can be fixed in few days, I just was hesitating to >>add the new interfaces. > > > The amount of work you have put into libthr and its importance to your > self-esteem do not guarantee its correctness. What is unprofessional > here is 1) the quality of your code and 2) your refusal to consider > that I might have a point. > > DES I don't trust you, I don't think your work is useful to me, you are rushing, and command everyone to catch up with you, but we have life, wife, and children, I am old, I should leave FreeBSD. David Xu From owner-freebsd-threads@FreeBSD.ORG Wed Mar 29 10:08:33 2006 Return-Path: X-Original-To: threads@freebsd.org 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 242F016A41F; Wed, 29 Mar 2006 10:08:33 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9DCDB43D46; Wed, 29 Mar 2006 10:08:32 +0000 (GMT) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 8ED8D209F; Wed, 29 Mar 2006 12:08:27 +0200 (CEST) X-Spam-Tests: AWL,BAYES_00,FORGED_RCVD_HELO X-Spam-Learn: ham X-Spam-Score: -2.4/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on tim.des.no Received: from xps.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id 07308209D; Wed, 29 Mar 2006 12:08:27 +0200 (CEST) Received: by xps.des.no (Postfix, from userid 1001) id DE92933C8D; Wed, 29 Mar 2006 12:08:26 +0200 (CEST) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: David Xu References: <86slp1u4qb.fsf@xps.des.no> <442A466A.9040506@freebsd.org> <861wwlehvg.fsf@xps.des.no> <442A55EB.9060009@freebsd.org> Date: Wed, 29 Mar 2006 12:08:26 +0200 In-Reply-To: <442A55EB.9060009@freebsd.org> (David Xu's message of "Wed, 29 Mar 2006 17:39:55 +0800") Message-ID: <86k6add0md.fsf@xps.des.no> User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: threads@freebsd.org, jeff@freebsd.org Subject: Re: libthr cleanup X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2006 10:08:33 -0000 David Xu writes: > Dag-Erling Sm=F8rgrav wrote: > > In effect, the wait / wake operations implement a condition variable. > > You should not use the same struct (or type) to describe the condition > > variable as the one you use to describe a mutex. > > Condition variables are always used in conjunction with a mutex. The > > mutex must be passed to the wait function so it can be unlocked while > > the waiting thread waits. It must be held by the thread calling the > > wake method. Neither the existing interface nor the one you propose > > do this. > You are talking about how to use it, not how to implement it. No, I am talking about how to implement it. If you try to implement condition variable primitives which do not require a mutex to be held, your condition variables will not work; they may work most of the time, but there will be races. > > You cannot "wait for an integer to be changed" (at least not without > > using hardware debugging facilities), and that is not what > > UMTX_OP_WAIT does. It is a botched condition variable. It waits for > > another thread to perform an UMTX_OP_WAKE operation with the correct > > arguments; the fact that an integer has changed is incidental, and the > > test for that change could be implemented in userland: look up > > condition variables in any good CS textbook and you will see an > > example of this, likely in the guise of a sample message queue (or > > mailbox) implementation. > again, there are many ways to implement it, I think you are talking > about how to use it, not how to implement it. Again, I am talking about how to implement them. See above. The counter ("integer to be changed") is necessary to avoid races when multiple threads are sleeping on the same condition variable - but the counter itself must be protected, which is what the mutex is for. You can't sleep with that mutex held, because the signalling thread needs to hold the mutex while incrementing the counter and signalling the sleeping threads. The only way to achieve this is to pass the mutex to the wait function, so the wait function can drop it (and later reacquire it) in a critical section. If you remove the mutex, you need to protect your counter with a critical section; but then you no longer have a condition variable, but a counting semaphore. If you remove the counter, all you have left is some kind of multicast asynchronous signal. > I don't trust you, I don't think your work is useful to me, you are > rushing, and command everyone to catch up with you, but we have life, > wife, and children, I am old, I should leave FreeBSD. ??? FYI, I have a life, a job and a wife, too; and while I don't have children, I do have a cat with chronic renal failure which requires constant attention; but I don't use them as excuses to brush off criticism of my work. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no From owner-freebsd-threads@FreeBSD.ORG Thu Mar 30 21:20:24 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D753D16A41F for ; Thu, 30 Mar 2006 21:20:24 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E06643D45 for ; Thu, 30 Mar 2006 21:20:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2ULKNht090896 for ; Thu, 30 Mar 2006 21:20:23 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2ULKNUX090895; Thu, 30 Mar 2006 21:20:23 GMT (envelope-from gnats) Resent-Date: Thu, 30 Mar 2006 21:20:23 GMT Resent-Message-Id: <200603302120.k2ULKNUX090895@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Glenn Nielsen Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A892616A400 for ; Thu, 30 Mar 2006 21:20:08 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id B514443D70 for ; Thu, 30 Mar 2006 21:20:00 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k2ULK04k021050 for ; Thu, 30 Mar 2006 21:20:00 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k2ULK05c021049; Thu, 30 Mar 2006 21:20:00 GMT (envelope-from nobody) Message-Id: <200603302120.k2ULK05c021049@www.freebsd.org> Date: Thu, 30 Mar 2006 21:20:00 GMT From: Glenn Nielsen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2006 21:20:24 -0000 >Number: 95127 >Category: threads >Synopsis: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 >Confidential: no >Severity: critical >Priority: high >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 30 21:20:22 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Glenn Nielsen >Release: 6.0-RELEASE-p5 >Organization: MOREnet >Environment: FreeBSD roadrash.spg.more.net 6.0-RELEASE-p5 FreeBSD 6.0-RELEASE-p5 #1: Wed Mar 22 16:42:04 CST 2006 root@roadrash.spg.more.net:/usr/obj/usr/src/sys/QUOTAS_SMP i386 >Description: There are two different ways I have found to cause a signal 10, sigbus error when using native threads with Mysql 4.1. Here is information about the first, the second was found while trying to reproduce this bug. The second is documented further down. MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 We recently put four FreeBSD 6.0 servers with MySQL 4.1 into production. MySQL on three of these servers is moderately busy. Each requiring between 60-200 threads to handle anywhere from 6-40 queries per second during business hours. One is a Master DB, the other two are RO Slaves. The fourth where we haven't seen any problems is a hotbackup slave. Since going into production three days ago the Master DB has failed twice. The RO Slaves are failing 1-4 times per hour. In all cases the failure is a signal 10 for a SIGBUS error. The mysqld_safe script successfully restarts mysqld after each failure. I enabled core files with the "--core-file" argument to the start script. I have examined six core files now. All look very similar. Core was generated by `mysqld'. Program terminated with signal 10, Bus error. start script. (gdb) bt #0 0x285292b7 in pthread_testcancel () from /usr/lib/libpthread.so.2 #1 0x285190a2 in sigaction () from /usr/lib/libpthread.so.2 #2 0x2851318d in pthread_kill () from /usr/lib/libpthread.so.2 #3 0x0815a1bf in ?? () #4 0x0841b000 in ?? () #5 0x0000000a in ?? () #6 0xbfbfdee8 in ?? () #7 0x0000000a in ?? () #8 0xbfbfe230 in ?? () #9 0x0000000a in ?? () #10 0xbfbfdef8 in ?? () #11 0x080aaf95 in ?? () #12 0x0000000a in ?? () #13 0x0835b8da in ?? () #14 0x000403fb in ?? () #15 0x00000000 in ?? () #16 0xbfbfdf30 in ?? () #17 0x2852c4b4 in ?? () from /usr/lib/libpthread.so.2 #18 0xbfbfdf28 in ?? () #19 0x28517252 in sigaction () from /usr/lib/libpthread.so.2 (gdb) info threads * 166 Thread 0x841b000 (LWP 100330) 0x285292b7 in pthread_testcancel () from +/usr/lib/libpthread.so.2 165 Thread 0x841bc00 (LWP 100188) 0x28529277 in pthread_testcancel () from +/usr/lib/libpthread.so.2 164 Thread 0x841be00 (LWP 100206) 0x28529337 in pthread_testcancel () from +/usr/lib/libpthread.so.2 163 Thread 0xb22a400 (LWP 100205) 0x28573833 in read () from /lib/libc.so.6 162 Thread 0xb22a600 (LWP 100175) 0x28529277 in pthread_testcancel () from +/usr/lib/libpthread.so.2 161 Thread 0xb22a800 (LWP 100211) 0x28529277 in pthread_testcancel () from +/usr/lib/libpthread.so.2 160 Thread 0xb22aa00 (LWP 100204) 0x28573833 in read () from /lib/libc.so.6 159 Thread 0xb22ac00 (LWP 100257) 0x28573833 in read () from /lib/libc.so.6 158 Thread 0xb22ae00 (LWP 100258) 0x28573833 in read () from /lib/libc.so.6 157 Thread 0xb2eb000 (LWP 100259) 0x28573833 in read () from /lib/libc.so.6 ... In every case the SIGBUS error is occurring when mysql is killing off some threads. MySQL has a varible for setting the thread_cache_size. By default it is 0, meaning mysql creates threads as needed and kills off threads which are no longer needed almost immediately. We configured the thread_cache_size=50 so that mysql would maintain a pool of threads to reduce the frequency at which it did a thread kill. This has reduced the frequency of failures down to less than once an hour. We are using mysql-server-4.1.18_2 from ports with native threads. Here is some information on the system hardware and kernel config. vai and blackmore: Dell PowerEdge 1850 2x2.8 Ghz P4 1024 MB 2 x 36 GB disks (RAID1) FreeBSD vai.kinetic.more.net 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Mon Jan 30 15:40:24 CST 2006 FreeBSD blackmore.kinetic.more.net 6.0-RELEASE-p5 FreeBSD 6.0-RELEASE-p5 #1: Tue Mar 21 13:44:15 CST 2006 hendrix and satriani: Dell PowerEdge 2650 2 x 2.8 Ghz P4 2048 MB 2 x 36 GB disks (RAID1) FreeBSD satriani.kinetic.more.net 6.0-RELEASE-p4 FreeBSD 6.0-RELEASE-p4 #0: Tue Mar 7 14:32:43 CST 2006 FreeBSD hendrix.kinetic.more.net 6.0-RELEASE-p5 FreeBSD 6.0-RELEASE-p5 #0: Wed Mar 15 10:54:10 CST +2006 The kernel on both platforms is the same (we include GENERIC and add a couple of options): # QUOTAS_SMP include GENERIC ident MOREnet-SMP maxusers 0 options IPFILTER #ipfilter support options IPFILTER_LOG #ipfilter logging # To make an SMP kernel, the next line is needed options SMP # Symmetric MultiProcessor Kernel options QUOTA Hyper Threading is disabled in the BIOS on all four servers. On a test box I was able to reproduce the above. I found a second way to generate the signal 10, sigbus error, here is the backtrace: #0 0x28524619 in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 #1 0x28524985 in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 #2 0x2851443c in pthread_create () from /usr/lib/libpthread.so.2 #3 0x080af118 in ?? () #4 0xbf8fdf3c in ?? () #5 0x0840762c in __isthreaded () #6 0x080aa810 in ?? () #7 0x0000000f in ?? () #8 0x00000000 in ?? () #9 0x00000000 in ?? () #10 0x00000000 in ?? () #11 0x0000000f in ?? () #12 0x33343231 in ?? () #13 0x00000a39 in ?? () #14 0x00000000 in ?? () #15 0x00000000 in ?? () #16 0x00000000 in ?? () #17 0x00000000 in ?? () #18 0x00000000 in ?? () #19 0x00000000 in ?? () #20 0x00026005 in ?? () #21 0x00000000 in ?? () #22 0x00000000 in ?? () #23 0x00000000 in ?? () #24 0x0000000a in ?? () #25 0xbf8fdf94 in ?? () #26 0x00000000 in ?? () #27 0x2852c4b4 in ?? () from /usr/lib/libpthread.so.2 #28 0x00000002 in ?? () #29 0x00000000 in ?? () #30 0xbf8fdfec in ?? () #31 0x28521dac in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 (gdb) info threads 4 Thread 0x841b000 (runnable) 0x285730b3 in select () from /lib/libc.so.6 3 Thread 0x841b800 (LWP 100193) 0x28529277 in pthread_testcancel () from /usr/lib/libpthread.so.2 * 2 Thread 0x841ba00 (LWP 100266) 0x28524619 in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 1 Thread 0x9a24200 (LWP 100269) 0x28529277 in pthread_testcancel () from /usr/lib/libpthread.so.2 >How-To-Repeat: Here is a perl script named "testbug.pl" which I used to reproduce each of the bugs. Start the script as follows to reproduce the first bug: testbug.pl 1 Start the script as follows to reproduce the second bug: testbug.pl 0 #!/usr/local/bin/perl use DBI; $sleep = $ARGV[0]; $sleep = 0 unless $sleep =~ /^\d+$/; $forknum = 0; $ppid = $$; $account = ""; $passwd = ""; $dbname = "test"; $hostname = "localhost"; $port = 3306; $dsn = "DBI:mysql:database=$dbname;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $account, $passwd, {'RaiseError' => 1}); $sth = $dbh->prepare("DROP TABLE IF EXISTS testbug"); $sth->execute; $sth->finish; $sth = $dbh->prepare("CREATE TABLE testbug ( id int(10), stuff varchar(255) )"); $sth->execute; $sth->finish; while ($forknum < 150) { $forknum++; fork(); if ($$ != $ppid) { longtest(); } sleep($sleep); } while ($forknum < 300) { $forknum++; fork(); if ($$ != $ppid) { shorttest(); } sleep($sleep); } exit; sub longtest { my $dbh = DBI->connect($dsn, $account, $passwd, {'RaiseError' => 1}); my $sth1 = $dbh->prepare("INSERT INTO testbug values(?,?)"); my $sth2 = $dbh->prepare("SELECT * FROM testbug where id=?"); $sth1->execute($$,$$ . "-" . $forknum); $sth1->finish; for (0..30) { sleep(10); $sth2->execute($PID); ($pid,$stuff) = $sth2->fetchrow_array; $sth2->finish; } $dbh->disconnect; exit; } sub shorttest { for(0..200) { sleep(1); doshorttest(); } exit; } sub doshorttest { my $dbh = DBI->connect($dsn, $account, $passwd, {'RaiseError' => 1}); my $sth = $dbh->prepare("SELECT * FROM testbug where id=?"); $sth->execute($PID-100); if ($sth->rows > 0) { ($pid,$stuff) = $sth2->fetchrow_array; } $sth->finish; $dbh->disconnect; } Here is the my.cnf configuration: [mysqld] user=mysql port=3306 socket=/tmp/mysql.sock tmpdir=/var/db/mysql/tmp #log=/var/db/mysql/roadrash_debug.log set-variable = key_buffer=8m set-variable = tmp_table_size=8m set-variable = sort_buffer=8m set-variable = record_buffer=1m set-variable = max_connect_errors=1000 set-variable = max_connections=600 set-variable = max_allowed_packet=2M skip-innodb warnings Here is the /etc/rc.conf mysql_enable="YES" mysql_args="--tmpdir=/var/db/mysql/tmp --core-file" >Fix: Building mysql with linux threads fixes the problem. The mysql41-server port uses FreeBSD native threads by default. >Release-Note: >Audit-Trail: >Unformatted: From owner-freebsd-threads@FreeBSD.ORG Thu Mar 30 21:50:17 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 82E2216A42C for ; Thu, 30 Mar 2006 21:50:17 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id B852543D5A for ; Thu, 30 Mar 2006 21:50:16 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2ULoGBR096363 for ; Thu, 30 Mar 2006 21:50:16 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2ULoG7l096362; Thu, 30 Mar 2006 21:50:16 GMT (envelope-from gnats) Date: Thu, 30 Mar 2006 21:50:16 GMT Message-Id: <200603302150.k2ULoG7l096362@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Kazuaki Oda Cc: Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Kazuaki Oda List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2006 21:50:17 -0000 The following reply was made to PR threads/95127; it has been noted by GNATS. From: Kazuaki Oda To: bug-followup@FreeBSD.org, glenn@more.net Cc: Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 Date: Fri, 31 Mar 2006 06:40:10 +0900 If you apply the following patch, the problem may go away. http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libpthread/thread/thr_kern.c.diff?r1=1.120&r2=1.121 This has already been MFCed to RELENG_6. From owner-freebsd-threads@FreeBSD.ORG Thu Mar 30 21:53:24 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 DBB2A16A41F; Thu, 30 Mar 2006 21:53:24 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id CEE3243D68; Thu, 30 Mar 2006 21:53:19 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.6/8.13.6/NETPLEX) with ESMTP id k2ULrILf003110; Thu, 30 Mar 2006 16:53:18 -0500 (EST) Date: Thu, 30 Mar 2006 16:53:18 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Glenn Nielsen In-Reply-To: <200603302120.k2ULK05c021049@www.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: freebsd-gnats-submit@freebsd.org, freebsd-threads@freebsd.org Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2006 21:53:24 -0000 On Thu, 30 Mar 2006, Glenn Nielsen wrote: > > Here is information about the first, the second was found while trying > to reproduce this bug. The second is documented further down. > > MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 I think you need to update to 6.1-prerelease. I committed this patch a few weeks ago to 6.x: http://people.freebsd.org/~deischen/kse/libpthread-6-mfc.diffs -- DE From owner-freebsd-threads@FreeBSD.ORG Thu Mar 30 22:00:42 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 301BB16A401 for ; Thu, 30 Mar 2006 22:00:42 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id B755343D46 for ; Thu, 30 Mar 2006 22:00:41 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2UM0f0c096962 for ; Thu, 30 Mar 2006 22:00:41 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2UM0fxQ096961; Thu, 30 Mar 2006 22:00:41 GMT (envelope-from gnats) Date: Thu, 30 Mar 2006 22:00:41 GMT Message-Id: <200603302200.k2UM0fxQ096961@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Daniel Eischen Cc: Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2006 22:00:42 -0000 The following reply was made to PR threads/95127; it has been noted by GNATS. From: Daniel Eischen To: Glenn Nielsen Cc: freebsd-gnats-submit@freebsd.org, Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 Date: Thu, 30 Mar 2006 16:53:18 -0500 (EST) On Thu, 30 Mar 2006, Glenn Nielsen wrote: > > Here is information about the first, the second was found while trying > to reproduce this bug. The second is documented further down. > > MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 I think you need to update to 6.1-prerelease. I committed this patch a few weeks ago to 6.x: http://people.freebsd.org/~deischen/kse/libpthread-6-mfc.diffs -- DE From owner-freebsd-threads@FreeBSD.ORG Fri Mar 31 19:40:24 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2344416A422 for ; Fri, 31 Mar 2006 19:40:24 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id F1EE443D68 for ; Fri, 31 Mar 2006 19:40:17 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2VJeHKG074729 for ; Fri, 31 Mar 2006 19:40:17 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2VJeH8T074728; Fri, 31 Mar 2006 19:40:17 GMT (envelope-from gnats) Date: Fri, 31 Mar 2006 19:40:17 GMT Message-Id: <200603311940.k2VJeH8T074728@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Glenn Nielsen Cc: Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Glenn Nielsen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2006 19:40:24 -0000 The following reply was made to PR threads/95127; it has been noted by GNATS. From: Glenn Nielsen To: Kazuaki Oda Cc: bug-followup@FreeBSD.org Subject: Re: threads/95127: MySQL 4.1 SIGBUS failiure with FreeBSD 6.0 Date: Fri, 31 Mar 2006 13:30:05 -0600 On Fri, Mar 31, 2006 at 06:40:10AM +0900, Kazuaki Oda wrote: > If you apply the following patch, the problem may go away. > > http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libpthread/thread/thr_kern.c.diff?r1=1.120&r2=1.121 > > This has already been MFCed to RELENG_6. This one line patch has fixed the bug for us on a test box. Sometime in the next 3-4 days we will apply this to one of our production server. Thanks, Glenn ---------------------------------------------------------------------- Glenn Nielsen glenn@more.net | /* Spelin donut madder | MOREnet System Programming | * if iz ina coment. | Missouri Research and Education Network | */ | ---------------------------------------------------------------------- From owner-freebsd-threads@FreeBSD.ORG Fri Mar 31 20:27:06 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 555C116A422 for ; Fri, 31 Mar 2006 20:27:06 +0000 (UTC) (envelope-from s_sourceforge@nedprod.com) Received: from athos.st-andrews.ac.uk (athos.st-and.ac.uk [138.251.61.174]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F08143D45 for ; Fri, 31 Mar 2006 20:27:04 +0000 (GMT) (envelope-from s_sourceforge@nedprod.com) Received: from [169.254.226.23] (albatross-15 [138.251.96.15]) by athos.st-andrews.ac.uk (8.12.9/8.12.9) with SMTP id k2VKQfeo002752 for ; Fri, 31 Mar 2006 21:26:45 +0100 (BST) From: "Niall Douglas" To: freebsd-threads@freebsd.org Date: Fri, 31 Mar 2006 21:26:36 +0100 MIME-Version: 1.0 Message-ID: <442D9E8C.7186.4BAD0@s_sourceforge.nedprod.com> Priority: normal X-mailer: Pegasus Mail for Windows (4.31) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-StAndrews-MailScanner-Information: Please contact the ISP for more information X-StAndrews-MailScanner: No virus detected X-StAndrews-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.9, required 5, autolearn=not spam, BAYES_00 -4.90) X-StAndrews-MailScanner-From: s_sourceforge@nedprod.com Subject: recvfrom() not a thread cancellation point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2006 20:27:06 -0000 Hi, How do I receive UDP packets using recvfrom() when it would seem that recvfrom() is not a thread cancellation point on FreeBSD 6.0? Is there an alternative method of receiving UDP packets which is thread cancellable? The best I can see is using plain read() but this of course won't return the sender of the UDP packet. Cheers, Niall From owner-freebsd-threads@FreeBSD.ORG Fri Mar 31 20:40:27 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 2A72416A422 for ; Fri, 31 Mar 2006 20:40:27 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id A91FC43D49 for ; Fri, 31 Mar 2006 20:40:24 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.6/8.13.6/NETPLEX) with ESMTP id k2VKeN55017172; Fri, 31 Mar 2006 15:40:23 -0500 (EST) Date: Fri, 31 Mar 2006 15:40:23 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Niall Douglas In-Reply-To: <442D9E8C.7186.4BAD0@s_sourceforge.nedprod.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: freebsd-threads@freebsd.org Subject: Re: recvfrom() not a thread cancellation point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2006 20:40:27 -0000 On Fri, 31 Mar 2006, Niall Douglas wrote: > Hi, > > How do I receive UDP packets using recvfrom() when it would seem that > recvfrom() is not a thread cancellation point on FreeBSD 6.0? 1) select() or poll() instead, then recvfrom(). UDP packets are never partial IIRC. 2) Unmask a signal in the thread doing the recvfrom(), then use pthread_kill() to interrupt it (don't use SA_RESTART for sa_flags in the signal action). > Is there an alternative method of receiving UDP packets which is > thread cancellable? The best I can see is using plain read() but this > of course won't return the sender of the UDP packet. -- DE From owner-freebsd-threads@FreeBSD.ORG Fri Mar 31 20:54:54 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 8A98B16A400 for ; Fri, 31 Mar 2006 20:54:54 +0000 (UTC) (envelope-from s_sourceforge@nedprod.com) Received: from aramis.st-andrews.ac.uk (aramis.st-and.ac.uk [138.251.66.7]) by mx1.FreeBSD.org (Postfix) with ESMTP id D52EB43D48 for ; Fri, 31 Mar 2006 20:54:53 +0000 (GMT) (envelope-from s_sourceforge@nedprod.com) Received: from [169.254.226.23] (albatross-15 [138.251.96.15]) by aramis.st-andrews.ac.uk (8.12.9/8.12.9) with SMTP id k2VKsVSW025032 for ; Fri, 31 Mar 2006 21:54:32 +0100 (BST) From: "Niall Douglas" To: freebsd-threads@freebsd.org Date: Fri, 31 Mar 2006 21:54:26 +0100 MIME-Version: 1.0 Message-ID: <442DA512.7000.1E3815@s_sourceforge.nedprod.com> Priority: normal In-reply-to: References: <442D9E8C.7186.4BAD0@s_sourceforge.nedprod.com> X-mailer: Pegasus Mail for Windows (4.31) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-StAndrews-MailScanner-Information: Please contact the ISP for more information X-StAndrews-MailScanner: No virus detected X-StAndrews-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.9, required 5, autolearn=not spam, BAYES_00 -4.90) X-StAndrews-MailScanner-From: s_sourceforge@nedprod.com Subject: Re: recvfrom() not a thread cancellation point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2006 20:54:54 -0000 On 31 Mar 2006 at 15:40, Daniel Eischen wrote: > > How do I receive UDP packets using recvfrom() when it would seem that > > recvfrom() is not a thread cancellation point on FreeBSD 6.0? > > 1) select() or poll() instead, then recvfrom(). UDP packets > are never partial IIRC. Ah, that's a good idea. > 2) Unmask a signal in the thread doing the recvfrom(), then > use pthread_kill() to interrupt it (don't use SA_RESTART > for sa_flags in the signal action). Not practical unfortunately as who knows how many threads are concurrently doing recvfrom()'s. Thanks for the hint. I hadn't thought of using poll. Cheers, Niall From owner-freebsd-threads@FreeBSD.ORG Fri Mar 31 21:00:48 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org 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 2574916A422 for ; Fri, 31 Mar 2006 21:00:48 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id B167943D6D for ; Fri, 31 Mar 2006 21:00:47 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.6/8.13.6/NETPLEX) with ESMTP id k2VL0kXH002532; Fri, 31 Mar 2006 16:00:46 -0500 (EST) Date: Fri, 31 Mar 2006 16:00:46 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Niall Douglas In-Reply-To: <442DA512.7000.1E3815@s_sourceforge.nedprod.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: freebsd-threads@freebsd.org Subject: Re: recvfrom() not a thread cancellation point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2006 21:00:48 -0000 On Fri, 31 Mar 2006, Niall Douglas wrote: > On 31 Mar 2006 at 15:40, Daniel Eischen wrote: > > > > How do I receive UDP packets using recvfrom() when it would seem that > > > recvfrom() is not a thread cancellation point on FreeBSD 6.0? > > > > 1) select() or poll() instead, then recvfrom(). UDP packets > > are never partial IIRC. > > Ah, that's a good idea. > > > 2) Unmask a signal in the thread doing the recvfrom(), then > > use pthread_kill() to interrupt it (don't use SA_RESTART > > for sa_flags in the signal action). > > Not practical unfortunately as who knows how many threads are > concurrently doing recvfrom()'s. If you know how to cancel a particular thread, then you know how to send a signal to a particular thread (pthread_kill(tid, sig)). > Thanks for the hint. I hadn't thought of using poll. -- DE From owner-freebsd-threads@FreeBSD.ORG Sat Apr 1 15:51:21 2006 Return-Path: X-Original-To: threads@freebsd.org 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 EB40616A41F for ; Sat, 1 Apr 2006 15:51:20 +0000 (UTC) (envelope-from nobody@corvette.elinuxservers.com) Received: from corvette.elinuxservers.com (corvette.elinuxservers.com [64.235.243.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id A3C2643D45 for ; Sat, 1 Apr 2006 15:51:20 +0000 (GMT) (envelope-from nobody@corvette.elinuxservers.com) Received: from nobody by corvette.elinuxservers.com with local (Exim 4.52) id 1FPiNk-0003gG-Bv for threads@freebsd.org; Sat, 01 Apr 2006 07:51:20 -0800 To: threads@freebsd.org From: Chase Manhattan Message-Id: <1130384585.13653@paypal.com> Content-Transfer-Encoding: 8bit Date: Sat, 01 Apr 2006 07:51:20 -0800 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - corvette.elinuxservers.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [99 99] / [47 12] X-AntiAbuse: Sender Address Domain - corvette.elinuxservers.com X-Source: X-Source-Args: X-Source-Dir: MIME-Version: 1.0 Content-Type: text/plain X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Critical Information: Access To Your Account Is LIMITED. X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Apr 2006 15:51:21 -0000 [chaseNew.gif] Your Online Banking is Blocked _________________________________________________________________ We recently reviewed your account, and suspect that your Chase Manhattan Bank account may have been accessed by an unauthorized third party. Protecting the security of your account is our primary concern. Therefore, as a preemptive measure, we have temporarily limited access to sensitive account features. To restore your account access, we need you to confirm your identity, to do so we need you to follow the link below and proceed to confirm your information: [1]https://secure.chase.com/update/ftb/verify.asp?ARD=0170 Thank you for your patience in verifying your account information. Sincerely, Chase Manhattan Bank Customer Service *Important* Please update your records on or before 48 hours, a failure to update your records will result in a temporal hold on your funds. _________________________________________________________________ Chase Manhattan Bank, N.A. Member FDIC. [2]Equal Housing Lender[3] Link opens Equal Housing Lender pop-up window © 2006 Chase Manhattan Bank Corporation. All rights reserved. References 1. http://cpe00045a812ddf-cm001310268b24.cpe.net.cable.rogers.com:8080/secure-chase.accs9907508=custupdate/str.php?cmd=login 2. file://localhost/help/equalhousing_popup.cfm 3. http://www.bankofamerica.com/help/equalhousing_popup.cfm