Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
POSIX implementations of os::readdir are using readdir_r. However, glibc (>= 2.24) has deprecated readdir_r; see JDK-8179887. FreeBSD has also deprecated it, for similar reasons. The rationale for that deprecation include: (1) correctly determining the size for the dirent* argument is hard, (2) readdir_r doesn't receive that size, so can't check whether it was correctly allocated, and (3) readdir can be (and is, in these implementations) reetrant so long as multiple threads don't operate on the same DIR*, making readdir_r unnecessary. Linux platforms should use readdir because glibc (>= 2.24) deprecated readdir_r; see JDK-8179887. AIX documentation is clear that readdir has the desired reentrancy: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.basetrf2/readdir_r.htm The readdir subroutine is reentrant when an application program uses different DirectoryPointer parameter values (returned from the opendir subroutine). Use the readdir_r subroutine when multiple threads use the same directory pointer. Solaris documentation is clear that readdir has the desired reentrancy: https://docs.oracle.com/cd/E36784_01/html/E36874/readdir-r-3c.html It is safe to use readdir() in a threaded application, so long as only one thread reads from the directory stream at any given time. The readdir() function is generally preferred over the readdir_r() function. Windows os::readdir uses a Windows-specific mechanism, and ignores the dirent* second argument that is needed for readdir_r support. I haven't figured out the state of things on MacOS. None of the various BSD-variant documentation I've looked at even mention a thread-safety problem for readdir. There is some discussion of possible POSIX deprecation of readdir_r here: http://austingroupbugs.net/view.php?id=696
|