Does D have equivalent of Java util.concurrent?

Dibyendu Majumdar d.majumdar at gmail.com
Sun Apr 28 09:21:37 UTC 2019


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


I wasn't talking about the cost of passing data, more about the 
cost of operations with this.

Say we have something like this.


SomeFunc(data)
     various ops with data
     return data

There should not be any extra overhead in the 'ops' part above. 
In C++ if data was marked volatile, then there would be an 
impact, but not otherwise, apart from the standard optimisation 
rules to do with data escaping, or aliasing something.


More information about the Digitalmars-d mailing list