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

Document a little about how join blocks #340

Merged
merged 2 commits into from Sep 22, 2017

Conversation

Projects
None yet
3 participants
@cuviper
Copy link
Member

cuviper commented May 16, 2017

No description provided.

@cuviper

This comment has been minimized.

Copy link
Member Author

cuviper commented May 16, 2017

This is trying to address the misunderstanding noted in #338 (comment).

@ChristopherDavenport
Copy link
Contributor

ChristopherDavenport left a comment

This makes sense to me. I didn't always follow but this is more clear.

/// `join` is called within the pool, the calling thread still actively
/// participates in the thread pool. It will try to execute its own
/// closures first, but if one is stolen then it will look for other
/// work while waiting for that result to come back.

This comment has been minimized.

@nikomatsakis

nikomatsakis May 22, 2017

Member

I think we should specify something a bit stronger:

"When the calling thread T is in the thread-pool, it will begin by executing closure A, while advertising closure B for other threads to execute. If no other thread is available to execute closure B, then the calling thread will execute closure B once closure A completes.

"You can rely on the fact that closure A is executed to help balance the work-load between the two closures. For example, imagine you have a queue; you may wish to pop the first item and process that in closure A, then recursively process the rest of the queue in closure B. This way, if another thread comes along, it will do the work of splitting up the queue in parallel with processing the first item. If you instead had closure A split the queue, then your current thread would first eagerly create all parallel work items before doing any actual work, increasing the overall overhead."

This comment has been minimized.

@cuviper

cuviper May 23, 2017

Author Member

Hmm. I actually don't like that queue example much, because it will incur linear stack usage. I don't think it is a good pattern for us to suggest with join.

This comment has been minimized.

@nikomatsakis

nikomatsakis May 25, 2017

Member

Not the best example, I agree, but I think it's important to specify which will execute immediately and which is available for stealing. Maybe just delete the 2nd paragraph? Anybody who cares enough to be tuning like this will have all the info they need in the 1st paragraph (in that case, we could rewrite it to talk about stealing a bit, too, like "while making closure B available to be stolen"; I was trying to avoid jargon but maybe it's better this way, more precise -- we can always link to wikipedia or something).

be specific about which closure executes locally
Sometimes you want to know, and I think we can readily commit to the current behavior.

@nikomatsakis nikomatsakis merged commit ff57a02 into rayon-rs:master Sep 22, 2017

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@cuviper cuviper deleted the cuviper:join-block branch Sep 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.