Does D have equivalent of Java util.concurrent?

Russel Winder russel at winder.org.uk
Sun Apr 28 09:03:00 UTC 2019


On Sun, 2019-04-28 at 08:34 +0000, Dibyendu Majumdar via Digitalmars-d wrote:
> […]
> 
> I have to understand the model. Suppose some mutable data is 
> passed around between threads. I don't really know as I haven't 
> read this in detail - but my question is this: is there a cost to 
> accessing data across threads?

It depends what you mean by passing here: passing by value, i.e. making a copy
of the value and losing all reference to the original, can be fairly overhead
free; passing by reference always imposes some sort of overhead. This is for
all programming languages.

> As in C or C++ I would expect the cost to be zero unless marked 
> volatile.

I think you need to offer some examples here. As far as I am aware C++ has
overhead for dealing with mutable data between threads: unique_ptr and
shared_ptr are not zero cost.

Arguably Rust gets closest to zero cost by having a move by default and borrow
system that is checked at compile time. (For heap values referenced using an
Arc instance there is a runtime cost of type and accessibility checking.) C++
hasn't quite got there as yet.

> I admit I don't understand the model of memory access in D. It 
> seems that like Go, D is attempting to push a message passing 
> model - that's what I meant by 'imposing a model'.

Message passing is the One True Way™ of handling data in a parallel or
concurrent system – obviously safety requires pass by value rather than pass
by reference. Go has this right in the language except that it allows passing
pointers. Rust mostly has this right in the language with the futures package
(or equivalent in gtk-rs). D doesn't really have this right but is well on the
way. C++17 I haven't investigated properly, but C++14 was far, far, far from
doing the right thing, so I doubt C++17 has it right.

So you meant memory model and not programming model. C++, D, Rust, Go all have
memory models, as Java, Kotlin, etc. have. Indeed a programming language that
has concurrency and parallelism features in the language or standard library
that doesn't have a memory model has so many "undefined behaviours" as to be
nigh on useless.

-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20190428/dafd2a7f/attachment.sig>


More information about the Digitalmars-d mailing list