-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Add optional argument to Semaphore.release for releasing multiple threads #55187
Comments
Call sem.release(5) would have the same effect as: with lock:
for i in range(5):
sem.release() The use case is when a single semaphore is holding up multiple threads and needs to release them all. According to "The Little Book of Semaphores <http://greenteapress.com/semaphores/\>", this is a common design pattern. Basic patch attached. If the proposal meets with acceptance, will add tests and a doc update. |
Your patch uses tabs for indentation. Otherwise, looks good on the principle. |
Seems good to proceed as there are no dissenters. |
Updated patch (with tests and docs). |
Never know whether to comment on issue itself, but just in case: There are issues with the patch when n < 0 is passed, as n is not sanity checked, which would break the Semaphore invariant (value must be >= 0). n == 0 is also a weird value, but harmless if passed; release(0) would acquire and release the lock but otherwise act as a noop. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: