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.
On the practical side:
- D has easy parallel foreach in the standard library.
- D has easy TLS variables which can help in caching situations
from time to time (avoids a contention point). Not sure what they
are for else.
- D has pure which helps compiler disambiguate aliasing (a pure
function couldn't touch anything else that what is passed.)
On the "not sure if useful" side:
- D has a GC which helps in some lock-free situations.
- D has deep-const and immutable which can be shared between
threads without restrictions.
- D offers "shared" which can theorically help you signal things
that are shared between threads.
- synchronized classes and methods. But they are more a liability
that a positive, you can always make something finer-grained with
a mutex.