Siegfried Heintze
10/2/2002 5:49:00 AM
I don't understand the difference in thread safety between hashtable,
sortedlist and NamedValueCollection.
To quote the documentation "A Hashtable can safely support one writer and
multiple readers concurrently. To support multiple writers, all operations
must be done through the wrapper returned by the Synchronized method."
(1) Assuming I use the synchronized wrapper, does this mean I don't have to
use the lock statement in C# as long as there is a maximum of one writer?
What if I have multiple writers? Could I use a ReaderWriterLock?
How is this different than sorted list which says: "A SortedList can safely
support multiple readers concurrently, as long as the collection is not
modified. To guarantee the thread safety of the SortedList, all operations
must be done through the wrapper returned by the Synchronized method"
(2) How is this different from a Hashtable? Using the wrapper, reading does
not require a lock but writing does?
Now consider NamedValueCollection:
"This implementation does not provide a synchronized (thread-safe) wrapper
for a NameValueCollection, but derived classes can create their own
synchronized versions of the NameValueCollection using the
NameObjectCollectionBase.ICollection.SyncRoot property."
(3) Does this mean everything, must be done with a lock statement for
exclusive access? Why cannot two threads simultaneously read without
locking?