Can I lock(something) on one line in C#?
c#, locking, multithreading, syntax
Solution
Yes.
This is not related to lock. C# programs are expressed using statements. Using {} groups multiple statements as a block. A block can be used in the context where a single statement is allowed. See C# language specification section 1.5.
Problem
Will the _otherThing field below be protected by the locks? ``` class ThreadSafeThing { private readonly object _sync = new object(); private SomeOtherThing _otherThing; public SomeOtherThing OtherThing { get { lock(_sync) return _otherThing; } } public void UpdateOtherThing(SomeOtherThing otherThing) { lock(_sync) _otherThing = otherThing; } } ```