From owner-freebsd-questions Mon Feb 7 10:42: 5 2000 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by builder.freebsd.org (Postfix) with ESMTP id 388654307 for ; Mon, 7 Feb 2000 10:42:00 -0800 (PST) Received: (from bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) id KAA09079; Mon, 7 Feb 2000 10:14:38 -0800 (PST) Date: Mon, 7 Feb 2000 10:14:38 -0800 From: Alfred Perlstein To: Spidey Cc: Freebsd Questions Mailing list Subject: Re: PThreads Message-ID: <20000207101438.Y25520@fw.wintelcom.net> References: <14494.21789.847287.358066@anarcat.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <14494.21789.847287.358066@anarcat.dyndns.org>; from beaupran@iro.umontreal.ca on Mon, Feb 07, 2000 at 12:16:13AM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Spidey [000206 21:43] wrote: Content-Description: message body text > Hi! > > I am currently working on a program that needs pthreads. > > Is there some bugs in FBSD implementation of the pthreads? Because I'm > having serious problems here: no there is no bug. > The following code, when executed, gives me something really weird: [snip...] > Is there something I do not understand in pthreads or what??? yes, you can't possibly expect readdir() which returns a pointer to a _static_ structure to be thread safe the way you are using it. if you wanted to fix this, then I would strdup() the d_name in the main thread then pass it to the slave threads, (don't forget to free() it!) basically, you're relying on a race condition that the string in the dirent isn't over written by successive calls to readdir(), basically that your slave thread will run to completion before the main thread loops again doing a readdir() and clobbering your dirent. enjoy, -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message