Stop nulling out lock object in SemaphoreSlim (#24776)
authorStephen Toub <stoub@microsoft.com>
Sun, 26 May 2019 02:13:05 +0000 (22:13 -0400)
committerGitHub <noreply@github.com>
Sun, 26 May 2019 02:13:05 +0000 (22:13 -0400)
commit580152a50e4092d32c7d05ec876cd6976483ebf1
tree24534996fb2f31e560b1d4a3d02c83365a76ae49
parent83309575a1552e39fe505cbd883391f3dcbea8b4
Stop nulling out lock object in SemaphoreSlim (#24776)

SemaphoreSlim.Dispose nulls out its lock object, and that's then used as an indication in other methods whether they should throw ObjectDisposedException.  But nulling out an object used for synchronization in other methods is a bad practice, and while SemaphoreSlim.Dispose is not thread-safe to be used concurrently with other usage of the instance, it's still confusing when such usage leads to NullReferenceExceptions due to trying to lock on a null lock object.  This change just changes the lock to be readonly, always set, and then whether the instance has been disposed is just a value set on that object (such that it's no larger than it used to be).
src/System.Private.CoreLib/shared/System/Threading/SemaphoreSlim.cs