Re: Hashtable thread safety / documentation
- From: Marc Gravell <marc.gravell@xxxxxxxxx>
- Date: Thu, 12 Jul 2007 21:40:41 -0700
Well, reading on a hashtable is inherently a multi-step operation;
first it needs to find the right bucket (by taking the hash/mod of the
key), then look at each item in that bucket to see if it Equals() the
key. As such, it is already comparable to enumeration.
Personally, I have found very little use in the Synchronised wrappers;
if I wany to work with the container, I lock the container (or it's
SyncRoot, or a separate sync object; it doesn't matter as long as
everybody agrees). This approach keeps things nice and simple to
debug. It is the rarety that I *only* want to add to a collection;
most of the time I want to check the existing contents (ContainsKey,
ContainsValue, perhaps) and maybe add something as a result. The
Synchronised wrapper cannot support this, as the read and write are
not atomic. A "lock, (read/write), unlock" approach guarantees that I
have the collection to myself for a few moments and can trust the
contents.
Marc
.
- Prev by Date: Re: The best date store & calculation
- Next by Date: Re: read the values from a excel row
- Previous by thread: RE: Registering a custom DLL after deployment - advice?
- Next by thread: Re: Hashtable thread safety / documentation
- Index(es):
Relevant Pages
|