What is the closest to ConcurrentHashMap and NavigableMap in Java?

Russel Winder russel at winder.org.uk
Fri Nov 15 09:35:33 PST 2013


On Fri, 2013-11-15 at 18:03 +0100, ilya-stromberg wrote:
> On Friday, 15 November 2013 at 16:36:56 UTC, Jacek Furmankiewicz 
> wrote:
> > How can you achieve lock-free reads with the synchronized MyMap 
> > approach?
> 
> In this case you can use Readers-writer lock
> http://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock
> 
> It allows multiple reads and single write. I think that the 
> easiest way is use OS spesific function, for example 
> `pthread_rwlock_t` for POSX. Note that D supports C ABI, so you 
> can call any C function from D.
> 
> I don't know any D implementation of Readers-writer lock, but you 
> can ask this question - maybe it already exist.

Sorry to come in late on this one (and miss everything that comes
before).

The trend in the JVM-verse is very much "if you use synchronized or an
explicit lock, and you are not creating a core library data structure,
you are doing it wrong". The background is that the whole purpose of a
lock it to control concurrency and thus stop parallelism. Applications
programmers should never have to use a lock. ConcurrentHashMap, and
thread safe queues are two consequences of all this.

In the Go-verse the attitude is basically the same, you should use
channels and communications – the synchronization is managed by the data
structure.

If D programmers are being told to use locks in applications code, then
the D programming model and library are failing. Or the advice is
wrong ;-)

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



More information about the Digitalmars-d-learn mailing list