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

Ensure context guard is !Send #239

Merged
merged 1 commit into from
Oct 2, 2020
Merged

Ensure context guard is !Send #239

merged 1 commit into from
Oct 2, 2020

Conversation

jtescher
Copy link
Member

@jtescher jtescher commented Oct 2, 2020

Currently you can hold a ContextGuard across await points accidentally via something like:

async {
    let cx = Context::current();
    let _g = cx.attach();
    some_future.await;
    // ...
}

This may cause inconsistent and buggy behavior as ContextGuards rely on thread locals, this change causes the compiler to catch this case by marking the guard as !Send though a phantom type that is !Send.

@jtescher jtescher requested a review from a team October 2, 2020 04:21
Copy link
Member

@frigus02 frigus02 left a comment

Choose a reason for hiding this comment

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

Oh nice. I remember wondering about this a while back. Looks good 👍

@jtescher jtescher merged commit c5297d2 into master Oct 2, 2020
@jtescher jtescher deleted the not-send-context-guard branch October 2, 2020 16:11
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