-
Notifications
You must be signed in to change notification settings - Fork 507
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
[Do not merge] Changes to Rayon in fork for rustc #569
Conversation
1e863f4
to
c3533d3
Compare
Can you give a high level summary of what the changes are, and why they are needed? |
I've made a commit for each feature added.
|
} | ||
|
||
/// Sets the current thread-local value | ||
pub fn set(value: usize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so this is some sort of "token" where:
- it starts as 0
- you can set it and get it
- when you spawn a job, it inherits the value at the time that job was spawned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
/// The type for a closure that gets invoked with a | ||
/// function which runs rayon tasks. | ||
/// The closure is passed the index of the thread on which it is invoked. | ||
/// Note that this same closure may be invoked multiple times in parallel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this distinct from the StartHandler
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, it kind of "takes over" the thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows up to run code both before and after the Rayon worker, so it is more powerful than StartHandler
and ExitHandler
. You can see it used here.
rayon-core/src/thread_local.rs
Outdated
|
||
impl<T> ThreadLocal<Vec<T>> { | ||
/// Joins the elements of all the thread locals into one Vec | ||
pub fn join(self) -> Vec<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from this method, I believe we could just use a "regular" thread-local value, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if @cuviper's "broadcast" primitive could be used to simulate this from a regular thread-local. I don't remember if it lets you return values — but it probably could. =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If by "regular" thread-local value, you mean something like the thread_local crate, then yes. However that is less efficient since it doesn't exploit the fact that our thread pool has a fixed number of threads.
My take on these changes:
|
I think we can close this – we are currently issuing |
This just shows to changes intended for use in rustc via a rustc_rayon and rustc_rayon_core fork of Rayon.