Noticed while reviewing #97227
The acquisition path tries to acquire the lock under try
I assume the purpose of that is to catch exceptions that may come from the event source, which is external code.
Since we may see exception after the lock is already in acquired state, the catch should release the lock, but instead it unregisters a waiter.
|
catch // run this code before exception filters in callers |
|
{ |
|
State.UnregisterWaiter(this); |
|
throw; |
|
} |
I think it would be unexpected for the caller that a failed attempt to acquire could leave the lock in a locked state. Worst case the calling thread will terminate while leaving behind an acquired lock, which is UB.