Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Feb 2000 10:14:38 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        Spidey <beaupran@iro.umontreal.ca>
Cc:        Freebsd Questions Mailing list <freebsd-questions@FreeBSD.ORG>
Subject:   Re: PThreads
Message-ID:  <20000207101438.Y25520@fw.wintelcom.net>
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
References:  <14494.21789.847287.358066@anarcat.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* Spidey <beaupran@iro.umontreal.ca> [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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000207101438.Y25520>