Skip to content

Improve documentation on thread::park returning spuriously #26475

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

Closed
aidanhs opened this issue Jun 21, 2015 · 5 comments
Closed

Improve documentation on thread::park returning spuriously #26475

aidanhs opened this issue Jun 21, 2015 · 5 comments

Comments

@aidanhs
Copy link
Member

aidanhs commented Jun 21, 2015

I'm aware that currently there is no way a thread can return from park spuriously, but this is an implementation detail - when/if the new implementation happens it will break anything trying to use park because there was previously no way to use it correctly.

(it may be that I've just missed how to do this, in which case I'd consider it a documentation bug and can make a PR)

@aidanhs aidanhs changed the title No way to tell if thread::park has returned spuriously No documented way to tell if thread::park has returned spuriously Jun 21, 2015
@alexcrichton
Copy link
Member

I believe that this is an intentional aspect of the thread::park API, so I believe the docs may just want to be clearer that spurious wakeups can happen and consumers must be prepared for that eventuality.

@aturon would know for certain, though.

@steveklabnik
Copy link
Member

Marking with libs until we know for sure.

@aturon
Copy link
Member

aturon commented Jun 23, 2015

Yes, it is intended to allow spurious wakeups in the future, with no way to detect them -- part of the point of this API is to impose the narrowest possible requirements on the underlying system (so as to use Futexes, etc, eventually).

@aturon
Copy link
Member

aturon commented Jun 23, 2015

(See the park method in http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/LockSupport.html, which is the inspiration.)

@aidanhs
Copy link
Member Author

aidanhs commented Jun 24, 2015

That's a good page.

The park method may also return at any other time, for "no reason", so in general must be invoked within a loop that rechecks conditions upon return. In this sense park serves as an optimization of a "busy wait" that does not waste as much time spinning, but must be paired with an unpark to be effective.

The second sentence in particular gives some clarity.

@aidanhs aidanhs changed the title No documented way to tell if thread::park has returned spuriously Improve documentation on thread::park returning spuriously Jun 24, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jul 21, 2015
bors added a commit that referenced this issue Jul 21, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Fixes #26475 

I'm not sure this is enough, really, but I'm not totally clear on what specific information would be valuable here. In the original issue, the Java page was pretty decent, but now I can't think of a different way to word it, and copying their prose is of course not acceptable.

thoughts @alexcrichton @aturon @aidanhs ?
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

No branches or pull requests

4 participants