Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Feb 2000 15:16:28 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        hackers@freebsd.org
Cc:        jasone@freebsd.org
Subject:   (forw) Re: readdir_r thread safe?
Message-ID:  <20000205151627.W25520@fw.wintelcom.net>

next in thread | raw e-mail | index | archive | help
Ugh, I should have brought this up before the code freeze but...

Maybe we could make 4.0 the transition point for adding locking
structures to FILE and DIR structures instead of the hackish
way it's done now (maintaining a seperate structure).

Does anyone agree or have time for this?

It would greatly simplify the code and actually fix the readdir_r
problem.

-Alfred

----- Forwarded message from "Richard Seaman, Jr." <dick@tar.com> -----

Date: Mon, 29 Nov 1999 15:32:50 -0600
From: "Richard Seaman, Jr." <dick@tar.com>
To: Alfred Perlstein <bright@wintelcom.net>
Cc: deischen@freebsd.org, jasone@freebsd.org, bde@freebsd.org
Subject: Re: readdir_r thread safe?
Message-ID: <19991129153250.F29767@tar.com>
X-Mailer: Mutt 1.0pre3i

On Mon, Nov 29, 1999 at 01:45:14PM -0800, Alfred Perlstein wrote:

> > I think the argument is more like what happens with the stream
> > functions fread(), fwrite(), etc.  There are the flockfile() and
> > funlockfile() functions that are used within libc and libc_r to
> > lock the FILE structure.  Locking the file descriptor element of
> > the FILE structure is not sufficient.  Moreover, its not the
> > programmmer's responsibility to lock the FILE structure before
> > accessing the stream functions.  libc does it for you.  I think
> > this is what it means to be "thread safe".
> 
> Ok, that makes sense.
> 
> > Now, if you don't want readdir_r() to be "thread safe", and document
> > it as such, that's another matter.  
> 
> That's not my intention, I'll see what I can do to fix this.

And now.... you're about to open a "can of worms". :)

The simplest way, by far, to have implemented flockfile() and 
funlockfile() would have been to add an element to the FILE
structure to hold the lock.  The simplest way, by far, to lock
the DIR structure is to modify the DIR structure to hold a lock
element.  Ditto for any other libc shareable structures, if there
are any.

But, I think this breaks compability, and would require a version
bump for libc.  I think this is why John Birrell implemented
flockfile() etc. in the very convoluted way he did (it was the
only other choice).

I don't know what every one thinks about a version bump for libc,
but I think there are enough thread related changes that libc
requires that it should happen.  But, probably someone needs to
wade through libc and find *all* the changes that are needed,
so that if the version bump is agreed to, it only happens once.
I started work on this about 9 months ago, got waylaid, and never
finished.

The alternative "hack" for the DIR structure that might work is
to lock the dd_fd every time you access the DIR structure, even
if you're not doing a file access.  This might be equivalent to
locking the DIR structure, but I haven't investigated it fully.

-- 
Richard Seaman, Jr.           email: dick@tar.com
5182 N. Maple Lane            phone: 262-367-5450
Chenequa WI 53058             fax:   262-367-5852

----- End forwarded message -----

-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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