[concurrency-interest] Concurrent Bidirectional Map

Dhanji R. Prasanna dhanji at gmail.com
Sun Nov 22 18:11:57 EST 2009

On Sun, Nov 22, 2009 at 2:52 PM, David Holmes <davidcholmes at aapt.net.au>wrote:

> Norman,
> Norman Elton writes:
> > Dhanji R. Prasanna writes:
> > > Also, in your implementation, in order for the bi-map-put to be
> > > perceived atomically, you would have to synchronize the get
> > > method as well =(
> >
> > This is where I'm a little perplexed. I've synchronized any write
> > methods, so that the two CHMs stay "in synch". Any read operations, as
> > I see it, should be safe to fall through to the primary CHM without
> > extra synchronization. If one thread is updating the map while another
> > is reading, the reading thread will either get the new or the old
> > value, but we shouldn't get any exceptions or end up with inconsistent
> > CHMs.
> >
> > Or am I misunderstanding something?
> Your reader thread can access the map while only one of the associations is
> in effect.

Yea, the update to both maps is not atomic because reader threads can
interleave between writes to either map. Technically, you won't corrupt the
map (unlike in the case of a regular HashMap), but that depends on what your
definition of corruption is (as David says). A read from the value->key map
can be inconsistent with a put to the key->value map.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20091122/c7f08ba9/attachment.html>

More information about the Concurrency-interest mailing list