Is it safe to use a boxed value type as a locker for the lock statement?
问题 The documentation of the lock statement is pretty straightforward: lock (x) { // Your code... } where x is an expression of a reference type . So I should not be allowed to pass a value type as locker for a lock . I noticed though that I can use a value type that implements an interface. In other words I can do this: IDisposable locker = default(DisposableStruct); lock (locker) Console.WriteLine("Thread safe"); struct DisposableStruct : IDisposable { public void Dispose() { } } This was