"Spawn as many thousand threads as you like" and D

Bienlein via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 16 07:43:18 PDT 2014


On Wednesday, 16 April 2014 at 14:21:03 UTC, Sönke Ludwig wrote:

> I still don't understand what you mean by "distributed". 
> Spawning 50.000 tasks:
>
> 	import vibe.core.core;
> 	import std.stdio;
> 	
> 	void main()
> 	{
> 	    foreach (i; 0 .. 50_000)
> 		runTask({
> 			writefln("Hello, World!");
> 		});
> 	}
>
> Alternatively, runWorkerTask will also distribute the tasks 
> among a set of worker threads, which would be more in line with 
> Go AFAIK.

All right, I see. I spent some time looking at the vibe.d 
homepage and I never saw any other code than something like this:

shared static this()
{
	auto settings = new HTTPServerSettings;
	settings.port = 8080;

	listenHTTP(settings, &handleRequest);
}

void handleRequest(HTTPServerRequest req,
                    HTTPServerResponse res)
{
	res.writeBody("Hello, World!", "text/plain");
}

Not wanting just to be right, but things like that should still 
be in some base library of the language and not in some 3rd party 
library. The vibe.d homepage says "As soon as a running fiber 
calls a special yield() function, it returns control to the 
function that started the fiber.". Yielding in the FiberScheduler 
by Sean Kelly is transparent. That's an important point to be 
easy to use, I think. Also the use of libevent is mentioned. I 
don't understand what the implications of that exactly is.

What I mean is that some nice transparent solution in a base 
library for the "some ten thousand threads thing" would be nice.


More information about the Digitalmars-d mailing list