You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to understand what the intended behavior is supposed to be when acquiring a semaphore and changing the max at the same time to a lower number. Here is an example:
# First acquire should work
iex(1)> Semaphore.acquire(:a, 5)
true
iex(2)> Semaphore.count(:a)
1
# Increasing the max and acquire again
iex(3)> Semaphore.acquire(:a, 7)
true
iex(4)> Semaphore.count(:a)
2
# Acquire with the same max
iex(5)> Semaphore.acquire(:a, 7)
true
iex(6)> Semaphore.count(:a)
3
# Now acquire with a lower max, shouldn't this return false?
iex(7)> Semaphore.acquire(:a, 2)
true
# This count feels a little disingenuous because of the previous statement returning true
iex(8)> Semaphore.count(:a)
2
What is the behavior supposed to be when lowering the max?
At first my intuition was that the count would be reset to 0, and that's why the iex(7) succeeded, but then when I look at the count I see 2, which is quite confusing. The 2 would make sense if the return value of iex(7) was false (i.e. the semaphore is still full but we now have a lower limit). Another possibility would be that changing the max via the acquire does not alter the count.
Additionally, I am not sure what the use case is for adjusting the max while acquiring at the same time. Would it makes things more clear to have a separate set_max function?
The text was updated successfully, but these errors were encountered:
TylerPachal
changed the title
Acquire behavior when changing counts
Behavior of acquire/2 when changing max
Apr 19, 2021
It would be nice if the count returned on iex(8) was 3, but with the current implementation using the ETS counter functions I don't think it is possible.
👋 Hello!
I am trying to understand what the intended behavior is supposed to be when acquiring a semaphore and changing the
max
at the same time to a lower number. Here is an example:What is the behavior supposed to be when lowering the max?
At first my intuition was that the count would be reset to 0, and that's why the
iex(7)
succeeded, but then when I look at the count I see 2, which is quite confusing. The 2 would make sense if the return value ofiex(7)
was false (i.e. the semaphore is still full but we now have a lower limit). Another possibility would be that changing the max via the acquire does not alter the count.Additionally, I am not sure what the use case is for adjusting the max while acquiring at the same time. Would it makes things more clear to have a separate
set_max
function?The text was updated successfully, but these errors were encountered: