What are the real advantages that D offers in multithreading?

cym13 via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 28 14:49:02 PST 2016


On Tuesday, 26 January 2016 at 11:44:56 UTC, nbro wrote:
> On Tuesday, 26 January 2016 at 11:41:49 UTC, nbro wrote:
>> Hi!
>>
>> I have seen that D offers basically similar constructs to Java 
>> for example for creating multithreaded applications. I would 
>> like to understand better what are the real advantages that D 
>> offers. Does D offer something that other known programming 
>> languages, such as C++, Java and Python, do not offer? An 
>> exhaustive explanation with concrete examples would be nice.
>
> Moreover, could you also explain why D was designed to 
> synchronize entire classes instead of single methods. If I 
> synchronize single methods (in Java for example), I could still 
> be able to use other non-synchronized methods without needing 
> to acquire the lock, so I don't understand this decision.

I don't know what was the decisive point of the decision but in 
can't help but note that it makes a lot of sense because D has 
functions.

Object methods are meant to be used with the encapsulated data. 
If it doesn't touch those data then it must be a function, it has 
nothing to do as a method. If it does touch those data then in 
multithreaded applications synchronizing only one amongst others 
doesn't make any sense: encapsulated data is a share resource. In 
java you don't have functions, only methods, so I sort-of 
understand why they did it that way. But in any other (sane?) 
language functions should be decoupled from methods anyway.


More information about the Digitalmars-d mailing list