Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Ensure fs::{DirEntry, ReadDir} are Send/Sync #22594

Merged
merged 1 commit into from
Feb 24, 2015

Conversation

alexcrichton
Copy link
Member

The windows/unix modules were currently inconsistent about the traits being
implemented for DirEntry and there isn't much particular reason why the traits
couldn't be implemented for ReadDir and DirEntry, so this commit ensures
that they are implemented.

Closes #22577

The windows/unix modules were currently inconsistent about the traits being
implemented for `DirEntry` and there isn't much particular reason why the traits
*couldn't* be implemented for `ReadDir` and `DirEntry`, so this commit ensures
that they are implemented.

Closes rust-lang#22577
@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa
Copy link
Member

nagisa commented Feb 20, 2015

There is a good reason to not implement them. Citing the linux man pages:

The data returned by readdir() may be overwritten by subsequent calls to readdir() for the same directory stream.

This opens doors to memory safety issues if a race condition appears. This means that we either have use a Mutex and sacrifice single-thread performance, or not implement Sync.

@nagisa
Copy link
Member

nagisa commented Feb 20, 2015

Looking at Windows’ implementation, I don’t see any synchronisation on a shared mutable data structure wfd either.
Nope, it is not shared, my bad.

@alexcrichton
Copy link
Member Author

There is a good reason to not implement them. Citing the linux man pages:

The data returned by readdir() may be overwritten by subsequent calls to readdir() for the same directory stream.

This is quite true! It is also why we do not use readdir :). We use readdir_r where we pass in our own allocated buffer which is then owned by the DirEntry. This means that, like windows, each DirEntry owns its contents and is completely isolated from all others (hence my believe it grants Send and Sync)

@nagisa
Copy link
Member

nagisa commented Feb 20, 2015

Ah +1 then.

@aturon
Copy link
Member

aturon commented Feb 21, 2015

@bors: r+ 756210a

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2015
 The windows/unix modules were currently inconsistent about the traits being
implemented for `DirEntry` and there isn't much particular reason why the traits
*couldn't* be implemented for `ReadDir` and `DirEntry`, so this commit ensures
that they are implemented.

Closes rust-lang#22577
@bors bors merged commit 756210a into rust-lang:master Feb 24, 2015
@alexcrichton alexcrichton deleted the issue-22577 branch March 27, 2015 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send not implemented for std::fs::read_dir
5 participants