core.thread vs std.concurrency - which of them to use?
Petar
Petar
Thu Aug 6 23:14:38 UTC 2020
On Thursday, 6 August 2020 at 01:13:28 UTC, Victor L Porton wrote:
> When to use core.thread and when std.concurrency for
> multithreading in applications? Is one of them a preferred way?
Druntime's core.thread sets the foundation for D's
multi-threading (or at least the non-betterC foundation). On top
of it Phobos' std.concurrency and std.parallelism provide a
higher-level abstractions.
Which ones you should use depends on your application:
* If you want to build a web application, event loop is the way
to go -> look at libraries like vibe-d / vibe-core / event-code
(these I've ordered from high-level to lowe-level).
* If you want to speed up a computation, then you're likely
looking for data-parallelism -> look into std.parallelism and
only if you need more control you can consider core.thread
* If you need concurrency, either logical (represent different
"processes" like web requests, AI agents in a simulation, or say
simply remembering different states of a graph iteration) or
physical (using multiple cores to do things concurrently, but not
necessarily based on data-parallelism) look into std.concurrency.
* If want to build a library (e.g. event loop, task
system/future/promises/ reactive extensions, actor model, SCP,
etc.) then you need to understand how things work under the hood
and so I'd say that reading core.thread's source code would be
valuable.
Cheers,
Petar
More information about the Digitalmars-d-learn
mailing list