[concurrency-interest] Concurrent Bidirectional Map

Norman Elton normelton at gmail.com
Sun Nov 22 23:25:50 EST 2009


> Suppose
> thread 1 is trying to set k -> v1
> while
> thread 2 is trying to set k -> v2
>
> Because the updates of the two maps are independent,
> and you can't control the scheduler, there is a risk of
> ending up with
> k -> v1
> in the first map, and
> v2 -> k
> in the reverse map
> in the quiescent state.

I've synchronized the put() methods in both directions back to a
single lock object, so one thread would block while the other
completes its update. Correct me if I'm wrong, this is definitely my
knowledge of the inner workings synchronization starts to get fuzzy.

Norman


More information about the Concurrency-interest mailing list