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

Implement thread::park and Thread::unpark #77

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

jamesbornholt
Copy link
Member

These were missing, as pointed out in #75. They're not too hard to implement---we just add an explicit park_state to each task.

There's a subtlety here in that park won't work well with futures due to our one-future-per-thread model, but the behavior of park within a future is probably unreliable on any realistic async runtime anyway. This is one of a class of behaviors around async that maybe we should have some way of warning about.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

let condvar = Arc::clone(&condvar);
thread::spawn(move || {
let mut guard = lock.lock().unwrap();
while !*guard {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think a better version of this test would be to replace the while with an if and then add an assert!(*guard) afterwards.

@jamesbornholt jamesbornholt merged commit bae3598 into awslabs:main Aug 23, 2022
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 this pull request may close these issues.

2 participants