-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
sync: add split
method to the permit types
#6472
Conversation
Add `detach` method to `SemaphorePermit` and `OwnedSemaphorePermit`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, such an api seems reasonable to me. I left a comment regarding the api.
I think |
Well, I chose the name
But if you insist, the name |
You use the name I suggested So I'd prefer |
Add `num_permits` method to `SemaphorePermit` and `OwnedSemaphorePermit`.
It's finished. |
detach
method to the permit typessplit
method to the permit types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Add
detach
method toSemaphorePermit
andOwnedSemaphorePermit
.Motivation
Assume there are two tasks named
A
andB
, and we have aSemaphore
with two permits.A
needs one permit,B
needs two permits at first and one permit later.If
B
executes first, it callsacquire_many
to get aSemaphorePermit
with two permits. After doing some work, one of the permits is unnecessary forB
to continue the work, but we can only release all permits at once.In this case,
A
has to wait untilB
finishes all works orB
releases its two permits and acquires one permit again to continue the remaining work without blockingA
.Since we have the
merge
method, I believe that the corresponding inverse operation is reasonable.Solution
Adds the
detach
method toSemaphorePermit
andOwnedSemaphorePermit
to allow us to detach some permits from the source permits.