"Spawn as many thousand threads as you like" and D
Bienlein via Digitalmars-d
digitalmars-d at puremagic.com
Wed May 7 14:32:47 PDT 2014
On Wednesday, 7 May 2014 at 17:13:07 UTC, Sönke Ludwig wrote:
>> The Tid handling is currently a little different, but apart
>> from that it
>> should work like this:
>>
>> import vibe.core.core;
>> import vibe.core.concurrency;
>>
>> void spawnedFunc(Tid tid)
>> {
>> receive(
>> (int i) { writeln("Received the number ", i); }
>> );
>> }
>>
>> // run it as a fiber in the same thread
>> // note: runTask only takes a delegate to make runTask({
>> ... })
>> // work without an ambiguity error
>> auto tid = runTask(toDelegate(&spawnedFunc),
>> Task.getThis());
>>
>> // or run it in the thread pool instead
>> runWorkerTask(&spawnedFunc, Task.getThis());
>>
>> Having said that, I'll just add a "thisTid" property to
>> vibe.core.concurrency to make that part API compatible. I'd
>> also add a
>> "spawn" alias, but the question is if that should point to
>> runTask or
>> rather to runWorkerTask.
>
>
> BTW, a runnable example can be found here:
> https://github.com/rejectedsoftware/vibe.d/blob/master/examples/message/source/app.d
Thanks for the quick answer. I'll give it a try ;-).
More information about the Digitalmars-d
mailing list