5

In the UNIX® System Threads Reference, under the heading of "Thread-safety" is a list of functions are "not guaranteed to be thread-safe on all UNIX systems." The function scandir() is absent from this list, while readdir() appears on the list.

However the glibc source for scandir() clearly appears to call readdir(), not the thread-safe readdir_r(). So was scandir() omitted from the list for some other reason, or is it thread-safe for some reason I am missing?

4

2 回答 2

1

似乎POSIX.1-2008指定它scandir()是线程安全的,因为它是POSIX.1-2008 函数,并且不在允许为非线程安全的函数列表中。但是,POSIX.1-2008 并不排除readdir()线程安全,在 glibc 的情况下,似乎readdir() 实际上是线程安全的,因为它不返回 global struct dirent,而是返回glibc 定义的成员调用DIR中返回的类型。opendir()

因此,即使 glibc 的scandir()调用readdir(),它似乎仍然是线程安全的。

于 2013-11-20T04:44:27.497 回答
1

我认为,此列表仅涵盖 POSIX 函数。 scandir(3)是 BSD/SVID,因此可能不会在此处列出。新的、线程安全的函数可能是这个列表的重点,但没有列出旧的、线程不安全的函数。

于 2013-11-18T18:44:46.570 回答