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
Is it okay to use libc::__errno_location with rayon? #1069
Comments
I think this is okay because you do nothing to yield into the thread pool between calling (Doing anything that yields control to Rayon might end up calling other code which messes with the thread-local variables. Similarly, each invocation of your closure could happen on a different thread of the pool and hence cannot communicate via thread-local storage.) |
Rayon doesn't move your closure once it's already running -- couldn't do that even if we wanted to, as you could have any kind of The point we're trying to make in those docs is that the closures that you pass to |
It is possible to create a thread very low-level way, so that thread-local storage doesn't work at all. For example, using Please, reword the docs such way that it will be clear that this is wrong interpretation. Write something like this: "Thread-local storage works. It is not UB to read it or write to it. It is okay to write to it and then immediately read from it. Just keep in mind that you cannot know where rayon will execute your code". Current text says "but they may have unexpected values". I can interpret this as |
Certainly not -- it would be a major library unsoundness if rayon allowed UB from safe user code. But I agree that "unexpected" is not clear, especially because that makes an assumption about what the user might be expecting. The TLS value may be different than the one where
/// # Warning: thread-local data
///
/// Because `op` is executing within the Rayon thread-pool,
/// thread-local data from the current thread will not be
/// accessible. But that's almost too strong -- you could end up executing on the same thread, if you call from within the pool in the first place. |
In my codebase I run
map
on rayon's parallel iterator, then inside map's closure I calllibc::linkat
and then I read errno like so:Is this okay?
https://docs.rs/rayon/1.7.0/rayon/fn.scope.html says:
This paragraph implies that in all threads executed in Rayon thread-pool one cannot access thread-local variables. And
map
execute its argument in Rayon thread-pool. Anderrno
(as well as I know) is thread-local variable. So, is it okay to accesserrno
in this code?The text was updated successfully, but these errors were encountered: