From owner-freebsd-doc Wed Jul 10 8:57:24 2002 Delivered-To: freebsd-doc@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9EC4137B400 for ; Wed, 10 Jul 2002 08:57:21 -0700 (PDT) Received: from mail.eecs.harvard.edu (bowser.eecs.harvard.edu [140.247.60.24]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2D55B43E4A for ; Wed, 10 Jul 2002 08:57:21 -0700 (PDT) (envelope-from fedorova@eecs.harvard.edu) Received: from wino.eecs.harvard.edu (wino.eecs.harvard.edu [140.247.62.200]) by mail.eecs.harvard.edu (Postfix) with ESMTP id 7027E54C543; Wed, 10 Jul 2002 11:57:20 -0400 (EDT) Received: from localhost (fedorova@localhost) by wino.eecs.harvard.edu (8.11.6+Sun/8.11.6) with ESMTP id g6AFvXE26747; Wed, 10 Jul 2002 11:57:33 -0400 (EDT) X-Authentication-Warning: wino.eecs.harvard.edu: fedorova owned process doing -bs Date: Wed, 10 Jul 2002 11:57:33 -0400 (EDT) From: "Alexandra (Sasha) Fedorova" To: Xavier.Leroy@inria.fr Cc: freebsd-doc@FreeBSD.ORG Subject: important linuxthreads documentation issue Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-doc@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Xavier, I just found an issue associated with using linuxthreads port on FreeBSD. It's an important point about how the library should be used, which must be documented somewhere (I spent a day trying to solve this problem, and if someone documents it, it will save other users lots of time). So here is the problem: - In the standard pthread.h file that comes in /usr/src/include on FreeBSD, pthread_mutex_t is defined as a pointer to struct pthread_mutex. - But, in the pthread.h file that comes with linuxthreads (/usr/local/include/linuxthreads/pthread/pthread.h), pthread_mutex_t is a struct itself! - So if you use the standard definition of pthread_mutex_t and then call pthread_mutex_init(pthread_mutex_t *, ...) of the linuxthread library, a disaster happens: since linuxthreads implementation expects a pointer to an allocated structure, it does not malloc anything, but goes and zeroes the fields of pthread_mutex_t. - You can see that if the standard definition of pthread_mutex_t is used. The standard definition provides to pthread_mutex_init a struct pthread_mutex**, a double pointer! So the user expects the library to allocate memory itself, which linuxthread library does not. As a result a disaster happens: the library writes into memory that belongs somewhere else in the program. ------ The key point here is that if someone is using a linuxthreads library on FreeBSD, they should use the right include file (/usr/local/include/linuxthreads/pthread/pthread.h), and also use -I/usr/local/include/linuxthreads/pthread option to gcc. If you think that this e-mail should be more appropriately addressed to someone else, please forward it to them. -- Sasha To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-doc" in the body of the message