Re: Hashtable thread safety / documentation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: The Computer Language Shootout Benchmarks
    ... The fact that the hashed_map container type ... Realloc may avoid this. ... existing items onto the new array. ... pointer to the next node in that bucket. ...
    (comp.lang.ada)
  • Re: cool morning
    ... Jack Hunt wrote: ... Any time you must leave a container of water outside where it will freeze, ... thus saving the bucket. ...
    (misc.rural)
  • Re: what makes it a balun????
    ... So you know how big the bucket was? ... I wound my first experimental 160 /M loading coil on a cardboard Vim ... container. ...
    (uk.radio.amateur)
  • Re: OT: Grammar
    ... I remember Stuart Gray saying ... Anyway, the bucket is the container, singular, so 'was' is correct. ...
    (uk.rec.motorcycles)
  • Re: [ckrm-tech] Circular Locking Dependency Chain detected in containers code
    ... holding container mutex. ... should be able to rmdir when a container is getting mounted. ... possible circular locking dependency detected] ... rmdir/4321 is trying to acquire lock: ...
    (Linux-Kernel)