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

Why is fs::Dir not Sync? #1230

Closed
nrath-js opened this issue Dec 2, 2024 · 2 comments · Fixed by #1232
Closed

Why is fs::Dir not Sync? #1230

nrath-js opened this issue Dec 2, 2024 · 2 comments · Fixed by #1232

Comments

@nrath-js
Copy link
Contributor

nrath-js commented Dec 2, 2024

I was surprised to see that the fs::Dir type is not marked as Sync.

As far as I can tell, all methods that access the internal state require a &mut self, so I think it's fine to use this type from multiple threads without the need for another mutex (since at most one thread can hold a &mut reference).

Am I missing something?

@sunfishcode
Copy link
Member

I think you're right; it could be Sync.

@notgull
Copy link
Contributor

notgull commented Dec 2, 2024

It is Sync on the linux_raw backend, but not the libc one.

nrath-js added a commit to nrath-js/rustix that referenced this issue Dec 3, 2024
This is safe since all methods that mutate the internal state require
a &mut self. It also makes behavior consistent with the linux_raw
backend (whose `fs::Dir` is Sync+Send).

Fixes: bytecodealliance#1230.
nrath-js added a commit to nrath-js/rustix that referenced this issue Dec 3, 2024
This is safe since all methods that mutate the internal state require
a &mut self. It also makes behavior consistent with the linux_raw
backend (whose `fs::Dir` is Sync+Send).

Fixes: bytecodealliance#1230.
sunfishcode pushed a commit that referenced this issue Dec 8, 2024
This is safe since all methods that mutate the internal state require
a &mut self. It also makes behavior consistent with the linux_raw
backend (whose `fs::Dir` is Sync+Send).

Fixes: #1230.
sunfishcode pushed a commit that referenced this issue Dec 8, 2024
This is safe since all methods that mutate the internal state require
a &mut self. It also makes behavior consistent with the linux_raw
backend (whose `fs::Dir` is Sync+Send).

Fixes: #1230.
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 a pull request may close this issue.

3 participants