Potencial problems in SemaphoreSlimExtensions class #16631
Replies: 2 comments
-
hi I will confirm that. Thanks for feedback. |
Beta Was this translation helpful? Give feedback.
0 replies
-
hi |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I see the source code of
SemaphoreSlimExtensions
class. I have a question on the methodTask<IDisposable> LockAsync(this SemaphoreSlim semaphoreSlim, int millisecondsTimeout)
The general way we use
Task<bool> WaitAsync(int millisecondsTimeout)
is like below:If we use
LockAsync
method inSemaphoreSlimExtensions
class, like below:I found some problems, if wait the mutex for 6s, and failed to get the mutex, it will still execute the code need to be locked. And there is no way to check whether entered the mutex successfully or not during the specific "TimeOut".
I code some demos to test the problem.
The result is expected
However, when I use
LockAsync()
, the result is unexpected.Duplicate number printed, the code was not locked as expected.
Am I misunderstand something, or it's a bug?
Beta Was this translation helpful? Give feedback.
All reactions