Is there an equivalent larynx in D?

I like Go, especially goroutines. They are simple and effective. After some digging, it seems that they are mostly connected to the fibers in the kernel thread pool (correct me if I am wrong).

As the saying goes, are there standard libraries (or relatively popular and supported third-party add-ons) in D?

The main thing I want:

  • Light threads use too much memory and take up too much CPU.
  • Simple communication is not too important, but simple messaging
  • Managed - it would be nice if it were at runtime

The main goal here is to make the web server as efficient as possible in order to compete with the speed of Node.js and Go. This means that there can be many active connections (http, websockets, streaming data).

I like things about the other platforms mentioned, but D is much more general. If he is not too clumsy, I would choose D over others.

+6
source share
3 answers

There is no equivalent for sure , but there are two modules that can provide something similar enough for your needs:

  • std.concurrency provides message passing and guaranteed isolation, unless the shared qualifier is used to get very limited explicit shared memory. However, you have not yet received fiber multiplexing on the threads that goroutines provide. Right now, every spawn call launches a new OS thread. In addition, some work still needs to be done to make the immutability sufficient for use so that this paradigm reaches its full potential. For more information about this paradigm, see the free chapter by Andrei Alexandrescu, "Programming Language D".

  • std.parallelism provides tasks. It focuses on parallelism, not concurrency. (This is not the same thing, even if you need concurrency to implement parallelism.) Therefore, instead of sending messages, the task simply runs without communication with the calling thread, and then returns the return value to the calling thread. In addition, if there are more tasks than threads, redundant tasks are queued rather than multiplexed using fibers.

Edit: I originally designed and wrote std.parallelism and would like to consider improvement requests according to needs like yours if they don't extend the scope of the module too far in the general case of concurrency. If std.parallelism does almost what you need, but not quite, send a function request either here or to the digitalmars.d newsgroup.

Also, although I probably would not be the developer of such a request, feel free to suggest improvements for std.concurrency.

+4
source

std.parallel uses threadpool to run tasks, however you will need to implement your own message passing procedures (currently there is no streaming network in the AFAIK library)

+2
source

I don't know if library D can provide support for split stacks (for threads / fibers). Without it, unfortunately, a lot of the usefulness of Go goroutines is lost.

If a problem is easily or better solved with goroutines, then why not just use Go first?

0
source

Source: https://habr.com/ru/post/903266/


All Articles