Jump to page: 1 2 3
Thread overview
What are the real advantages that D offers in multithreading?
Jan 26, 2016
nbro
Jan 26, 2016
nbro
Jan 26, 2016
Guillaume Piolat
Jan 28, 2016
Russel Winder
Jan 28, 2016
nbro
Feb 05, 2016
Russel Winder
Jan 28, 2016
cym13
Jan 29, 2016
Thiez
Jan 28, 2016
cym13
Jan 26, 2016
Kagamin
Jan 26, 2016
bachmeier
Jan 26, 2016
w0rp
Jan 26, 2016
Chris Wright
Jan 27, 2016
Kagamin
Jan 30, 2016
Sean Kelly
Feb 01, 2016
Kagamin
Jan 27, 2016
Brad Anderson
Jan 28, 2016
Kagamin
Jan 28, 2016
deadalnix
Jan 28, 2016
Brad Anderson
Jan 28, 2016
Chris Wright
Jan 28, 2016
Brad Anderson
January 26, 2016
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.
January 26, 2016
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.
January 26, 2016
D differs in how threads share data. See last chapters of tutorial: http://ddili.org/ders/d.en/index.html from "Parallelism" to "Fibers".
January 26, 2016
The most important thing D does, which is fundamentally different, is that variables are thread local by default, and you must opt-in to variables that are shared across threads. Immutable data can be shared implicitly, because there are no writers. This means that if you keep only a small amount of shared state, it should be easy to track down what could possibly be affected by multi-threading issues.

I haven't ever used synchronized classes myself, but it's probably a way of preventing mistakes where you synchronize some methods, but not others. You can also use synchronized {} blocks to introduce some recursive locking for a series of statements. So you could put that inside of a class method.
January 26, 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.


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.


January 26, 2016
On Tuesday, 26 January 2016 at 12:47:24 UTC, Kagamin wrote:
> D differs in how threads share data. See last chapters of tutorial: http://ddili.org/ders/d.en/index.html from "Parallelism" to "Fibers".

Also, the start of chapter 11 of Learning D has a discussion of these issues, and links to http://www.informit.com/articles/printerfriendly/1609144 (chapter of Andrei's book) and http://octarineparrot.com/article/view/getting-more-fiber-in-your-diet (article).
January 26, 2016
On Tue, 26 Jan 2016 11:41:49 +0000, nbro wrote:
> Does D
> offer something that other known programming languages, such as C++,
> Java and Python, do not offer?

D has in the standard runtime Fibers (aka coroutines).

You can use fibers in C++ if you find a library to do it (boost might?). You might be able to find a Java library for it, but it's difficult and might require bytecode rewriting. I think pypy has coroutines. But on the whole, it's a bear to find working coroutines in most languages.

Go has "goroutines", which are effectively coroutines that are entirely hidden from you. If you need to manage scheduling yourself, or you need to ensure that a particular thing is running all the time, this really isn't an option in Go.
January 27, 2016
On Tuesday, 26 January 2016 at 20:33:34 UTC, Chris Wright wrote:
> You can use fibers in C++ if you find a library to do it (boost might?). You might be able to find a Java library for it, but it's difficult and might require bytecode rewriting.

The java approach is Netty and NIO.
January 27, 2016
On Tuesday, 26 January 2016 at 20:33:34 UTC, Chris Wright wrote:
> On Tue, 26 Jan 2016 11:41:49 +0000, nbro wrote:
>> Does D
>> offer something that other known programming languages, such as C++,
>> Java and Python, do not offer?
>
> D has in the standard runtime Fibers (aka coroutines).
>
> You can use fibers in C++ if you find a library to do it (boost might?). You might be able to find a Java library for it, but it's difficult and might require bytecode rewriting. I think pypy has coroutines. But on the whole, it's a bear to find working coroutines in most languages.
>
> Go has "goroutines", which are effectively coroutines that are entirely hidden from you. If you need to manage scheduling yourself, or you need to ensure that a particular thing is running all the time, this really isn't an option in Go.

Yeah, boost can do fibers. ASIO has clever/hacky "stackless coroutines" and C++17 is going to add "stackless resumable functions" for async/await. D is about to lose a competitive advantage here.
January 28, 2016
On Wednesday, 27 January 2016 at 17:30:28 UTC, Brad Anderson wrote:
> Yeah, boost can do fibers. ASIO has clever/hacky "stackless coroutines" and C++17 is going to add "stackless resumable functions" for async/await. D is about to lose a competitive advantage here.

Isn't asio based on fibers just like vibe?
« First   ‹ Prev
1 2 3