This is the mail archive of the
mailing list for the libstdc++ project.
Re: [patch] libstdc++/67747 Allocate space for dirent::d_name
- From: Martin Sebor <msebor at gmail dot com>
- To: Florian Weimer <fweimer at redhat dot com>, Jonathan Wakely <jwakely at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 02 Oct 2015 11:37:55 -0600
- Subject: Re: [patch] libstdc++/67747 Allocate space for dirent::d_name
- Authentication-results: sourceware.org; auth=none
- References: <20150929113726 dot GU12094 at redhat dot com> <560E759E dot 2000005 at redhat dot com> <20151002123428 dot GP12094 at redhat dot com> <560EB776 dot 2090504 at gmail dot com> <560EBA49 dot 7050008 at redhat dot com>
On 10/02/2015 11:09 AM, Florian Weimer wrote:
On 10/02/2015 06:57 PM, Martin Sebor wrote:
Readdir isn't required to be thread-safe (it may reference global
data) so calling it in multiple threads even with a different dirp
argument is undefined. A thread-unsafe implementation can meet the
POSIX requirement and still access global data but without locking.
A readdir implementation which is not thread-safe when used with
different directory streams is just buggy. It may be conforming, but so
is an implementation that always fails with EOVERFLOW.
POSIX is clear: The readdir() function need not be thread-safe.
There's nothing wrong with relying on a function's thread safety
when it's documented to be thread safe by the implementation,
even if POSIX doesn't guarantee it. But doing so otherwise,
against both the standard and against the documentation, would
be risky to say the least.
The Solaris implementation, for example, is explicitly documented
as thread unsafe.
MT-safety is ambiguous for functions which operate on pointer arguments.
It is not clear if it is permitted to call the function without
synchronization on overlapping objects.
memcpy has the same thread-safety level as readdir on Solaris
I'm not sure what you are basing this assertion on. In the man
pages I have looked at, memcpy is documented as MT-Safe. readdir
is documented as MT-Unsafe. The Unsafe definition is clear:
contains global and static data that is not protected.
For example, Solaris 11.2: