What is the closest to ConcurrentHashMap and NavigableMap in Java?

TheFlyingFiddle theflyingfiddle at gmail.com
Thu Nov 14 13:16:13 PST 2013


> 2) Use `shared` storage class and mutex like this:
>
> import vibe.utils.hashmap;
>
> shared HashMap!(int, int) map;
>
> void foo()
> {
>    synchronized
>    {
>       //use map
>       map[1] = 1;
>    }
> }

Locking every time you use the map dosn't rly seem reasonable. 
It's not particulary fast and you might forget to lock the map at 
some point (or does the shared modifier not allow you to do this 
in D?)

I'm not that fammiliar with the synchronzed statement but 
shouldn't it be locked on some object?

void bar()
{
    //Can one thread be in this block...
    synchronized
    {
      map[1] = 1;
    }

    //... while another thread is in this block?
    synchronized
    {
      map[2] = 2;
    }
}

If that is the case are you not limited in the way you can update 
the map eg only in a single block?




More information about the Digitalmars-d-learn mailing list