[concurrency-interest] Concurrent Bidirectional Map

David Holmes davidcholmes at aapt.net.au
Sun Nov 22 17:52:52 EST 2009


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. Whether that can cause a problem in practice depends on the exact
semantics of the bi-map and how it is used. If you add the value->key
mapping before the key->value mapping (and remove in opposite order) then it
will mitigate the ability to see inconsistency - assuming you always lookup
by key, not value.

David Holmes

> Thanks again,
> Norman
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list