Skip to content

Create API for mutex that is always fair #204

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

Merged
merged 5 commits into from
Jan 10, 2020
Merged

Create API for mutex that is always fair #204

merged 5 commits into from
Jan 10, 2020

Conversation

paulocsanz
Copy link
Contributor

@paulocsanz paulocsanz commented Jan 6, 2020

Fixes #76. I don't know if there is interest in having a API for a Mutex that is always fair, but solving it at the type level seems better than requiring a state for each mutex. Fairness sometimes is required, so making type level assurances so another dev can't screw up may solve a bunch of problems, it's probably already being done by people that need it since it's just a thin wrapper.

This implements a FairMutex and it's RawFairMutex. This could be done for RwLock too if there is interest.

Idk if the tests are required since it's literally calling something already tested, but I just copied the files and made it compile. I had to remove the Condvar test, since Condvar assumes it's a MutexGuard, and doesn't accept a FairMutexGuard.

@Amanieu
Copy link
Owner

Amanieu commented Jan 9, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 9, 2020
Merge #204

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
204: Create API for mutex that is always fair r=Amanieu a=paulocsanz

Fixes #76. I don't know if there is interest in having a API for a Mutex that is always fair, but solving it at the type level seems better than requiring a state for each mutex. Fairness sometimes is required, so making type level assurances so another dev can't screw up may solve a bunch of problems, it's probably already being done by people that need it since it's just a thin wrapper. 

This implements a `FairMutex` and it's `RawFairMutex`. This could be done for RwLock too if there is interest.

Idk if the tests are required since it's literally calling something already tested, but I just copied the files and made it compile. I had to remove the Condvar test, since Condvar assumes it's a MutexGuard, and doesn't accept a FairMutexGuard.

Co-authored-by: Paulo <paulosanz@poli.ufrj.br>
@Amanieu
Copy link
Owner

Amanieu commented Jan 9, 2020

bors r-

@bors
Copy link
Contributor

bors bot commented Jan 9, 2020

Canceled

@Amanieu
Copy link
Owner

Amanieu commented Jan 9, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 9, 2020
Merge #204

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
204: Create API for mutex that is always fair r=Amanieu a=paulocsanz

Fixes #76. I don't know if there is interest in having a API for a Mutex that is always fair, but solving it at the type level seems better than requiring a state for each mutex. Fairness sometimes is required, so making type level assurances so another dev can't screw up may solve a bunch of problems, it's probably already being done by people that need it since it's just a thin wrapper. 

This implements a `FairMutex` and it's `RawFairMutex`. This could be done for RwLock too if there is interest.

Idk if the tests are required since it's literally calling something already tested, but I just copied the files and made it compile. I had to remove the Condvar test, since Condvar assumes it's a MutexGuard, and doesn't accept a FairMutexGuard.

Co-authored-by: Paulo <paulosanz@poli.ufrj.br>
@bors
Copy link
Contributor

bors bot commented Jan 10, 2020

@bors bors bot merged commit 2e5a7f8 into Amanieu:master Jan 10, 2020
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.

Consider making "fairness" something decided when a lock is created
2 participants