Semaphore doesn't raise exception when negative int passed to constructor
flash-gordon opened this issue · 3 comments
flash-gordon commented
The docs say it'll raise an error but it doesn't:
Concurrent::Semaphore.new(-1)I use cruby.
There's no check for negative number in the code:
https://github.dev/ruby-concurrency/concurrent-ruby/blob/385156117c110808875e1e87d5267147f696f796/lib/concurrent-ruby/concurrent/atomic/mutex_semaphore.rb#L12
eregon commented
Indeed, could you make a PR to add the check?
eregon commented
Looking more into this, it seems it's intended to allow a negative initial count since 736ebd1, which also adds a spec for Concurrent::Semaphore.new(-1).
So the docs are wrong and I'll update that.
Semaphore can go negative, that seems a common feature of semaphores.
eregon commented