G
Guest
I have a basic question regarding the Hashtable thread safety. According to
MSDN docs,
#1 Hashtable is thread safe for use by multiple reader threads, or a single
writing thread
#2 Synchronized supports multiple writing threads, provided that no threads
are reading the Hashtable. The synchronized wrapper does not provide
thread-safe access in the case of one or more readers and one or more writers
Section 2 basically says, multiple writers and no readers = ok, otherwise
you need to synchronize access yourself.
This seems to be out of sync with the behavior of the other collection
classes for which Synchronized method synchronizes all access when doing
individual operations like add, remove, read, update. Of course collection
enumeration is not thread safe. As an example look at SortedList.Synchronized.
The phrasing of the documentation seems strange to me, can somebody clarify
the behavior and confirm/deny if this is a documentation issue and Hashtable
behaves like all other collections?
MSDN docs,
#1 Hashtable is thread safe for use by multiple reader threads, or a single
writing thread
#2 Synchronized supports multiple writing threads, provided that no threads
are reading the Hashtable. The synchronized wrapper does not provide
thread-safe access in the case of one or more readers and one or more writers
Section 2 basically says, multiple writers and no readers = ok, otherwise
you need to synchronize access yourself.
This seems to be out of sync with the behavior of the other collection
classes for which Synchronized method synchronizes all access when doing
individual operations like add, remove, read, update. Of course collection
enumeration is not thread safe. As an example look at SortedList.Synchronized.
The phrasing of the documentation seems strange to me, can somebody clarify
the behavior and confirm/deny if this is a documentation issue and Hashtable
behaves like all other collections?