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

Allow lock guards to be sent to other threads #240

Merged
merged 3 commits into from
May 30, 2020
Merged

Allow lock guards to be sent to other threads #240

merged 3 commits into from
May 30, 2020

Conversation

Amanieu
Copy link
Owner

@Amanieu Amanieu commented May 27, 2020

But only if deadlock detection is not enabled.

Fixes #197

@Amanieu
Copy link
Owner Author

Amanieu commented May 28, 2020

cc @arthurprs

@bjorn3
Copy link
Contributor

bjorn3 commented May 28, 2020

Cargo expects features to be additive. This means that enabling features must never break code. It must only allow more code. By making the deadlock detection feature disable the Send impl for MutexGuard you are breaking code.

@arthurprs
Copy link
Contributor

While that's the expectation, there are lots and lots of examples of mutually exclusive features out there. But that's just my opinion.

@bjorn3
Copy link
Contributor

bjorn3 commented May 28, 2020

In those cases it is often choosing between two or more backends for a crate. This means that 1. the target executable is likely the one enabling the feature flag and 2. you can't accidentally depend on a feature flag being disabled, as you have to explicitly enable one feature flag to break another one. You can't just have a crate compiling with no feature flags enabled at all and then break when you enable one feature flag.

@bjorn3
Copy link
Contributor

bjorn3 commented May 28, 2020

A better alternative than simply breaking code when enabling the deadlock_detection feature flag would be to add a new sendable_guard feature flag to enable this and add a compile_error! when both feature flags are enabled. While this does still violate the additive assumption, this does makes it a lot harder to accidentally depend on the Sendness of lock guards.

@Amanieu
Copy link
Owner Author

Amanieu commented May 28, 2020

@bjorn3 That sounds like a great idea!

But only if deadlock detection is not enabled.

Fixes #197
README.md Outdated Show resolved Hide resolved
@Amanieu Amanieu force-pushed the send_guard branch 2 times, most recently from 227219e to cf9635d Compare May 30, 2020 13:03
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
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.

Sendable guards
3 participants