Does D have equivalent of Java util.concurrent?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri May 17 09:38:42 UTC 2019


On Sunday, 28 April 2019 at 09:03:00 UTC, Russel Winder wrote:
> 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.

A bit late reply, but unique_ptr is near zero cost, however, 
neither are thread safe.
For that you need to wrap the smart-pointer like 
std::atomic<std::shared_ptr<T>> (C++20).

Anyway, I'd argue that irrespective of language you might as well 
consider implementing your own shared store using CAS 
instructions and avoid locking altogether. If it fits what you 
want to do.

In D's typesystem that means that only the encapsulating 
datastructure would be shared and all the nodes would be 
nonshared (you acquire them using CAS).



More information about the Digitalmars-d mailing list