From owner-freebsd-current Sun Sep 20 12:25:53 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA20025 for freebsd-current-outgoing; Sun, 20 Sep 1998 12:25:53 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from smtp02.primenet.com (smtp02.primenet.com [206.165.6.132]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA20000 for ; Sun, 20 Sep 1998 12:25:35 -0700 (PDT) (envelope-from tlambert@usr04.primenet.com) Received: (from daemon@localhost) by smtp02.primenet.com (8.8.8/8.8.8) id MAA14657; Sun, 20 Sep 1998 12:24:52 -0700 (MST) Received: from usr04.primenet.com(206.165.6.204) via SMTP by smtp02.primenet.com, id smtpd014578; Sun Sep 20 12:24:41 1998 Received: (from tlambert@localhost) by usr04.primenet.com (8.8.5/8.8.5) id MAA26989; Sun, 20 Sep 1998 12:24:36 -0700 (MST) From: Terry Lambert Message-Id: <199809201924.MAA26989@usr04.primenet.com> Subject: Re: HighWind products To: info@highwind.com (HighWind Software Information) Date: Sun, 20 Sep 1998 19:24:36 +0000 (GMT) Cc: rotel@indigo.ie, tlambert@primenet.com, freebsd-current@FreeBSD.ORG, jb@cimlogic.com.au In-Reply-To: <199809201256.IAA06956@highwind.com> from "HighWind Software Information" at Sep 20, 98 08:56:41 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > } Subject: Re: HighWind products > > > } Subject: Re: HighWind products > > > > > > Looks like readdir() is MT safe anyhow. > > > > Only if you use seperate DIR descriptors per thread. > > Yeah, thats a good point, I expect this would be the scenario in > most programs, but I can think of some where it wouldn't. It means > that implementing readdir_r() is as easy as wrapping readdir() with > a lock though. > > We tried that. IT DID NOT WORK. We got all sorts of random memory > corruption with opendir(), lock, readdir(), unlock, closedir(). > > Perhaps the whole sequence needed to be locked? In opendir/readdir/telldir/seekdir/rewinddir/closedir, you need to lock access to the DIR *. You probably need to allocate the dd_loc/dd_buf/dd_len/dd_seek/dd_rewind members of the DIR * in thread local storage. In general, you can't expect to be able to split readdir calls between threads. The way readdir works is to call getdents to fill a user buffer, and then it traverses entries in the user buffer until it gets the last one, after which it calls getdents again. Basically, you have implied lseek context problems. So what is the correct behaviour when calling readdir in several threads on a single descriptor? I don't know... what behaviour are you expecting to have happen? Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message