I am new to SyncRoot concept. As far I can tell, the object used for locking should be private.
However HashTable
has a public property, SyncRoot
, which is just a wrapper over a private SyncRoot object. It is recommended that you lock on HashTable.SyncRoot
when enumerating over the collection.
It seems like we could fail with a dead lock since it is no longer private. Is it truly thread safe?
What if I make my own private locking mechanism?
private readonly object _syncObject;
Which one is better and why?