Using tasks without GC?

dwdv dwdv at posteo.de
Sat Jan 4 11:30:53 UTC 2020


> Creates a Task on the GC heap that calls an alias.

If possible, there's also scopedTask, which allocates on the stack: 
https://dlang.org/phobos/std_parallelism.html#.scopedTask

> So my question is: Has anyone done any analysis over how "dangerous" it is to use GC'd tasks for 
> _small_ tasks (in terms of milliseconds)?

Nothing major, but https://github.com/mratsim/weave/tree/master/benchmarks/fibonacci puts quite a 
bit of pressure on various implementations. You might want to profile ./pfib 40:

import std;

ulong fib(uint n) {
     if (n < 2) return n;

     auto x = scopedTask!fib(n-1); // vs. Task!fib(n-1);
     taskPool.put(x);
     auto y = fib(n-2);
     return x.yieldForce + y; // {yield,spin,work}Force
}

void main(string[] args) {
     enforce(args.length == 2, "Usage: fib <n-th fibonacci number requested>");
     auto n = args[1].to!uint;
     // defaultPoolThreads(totalCPUs);
     writefln!"fib(%d) = %d"(n, fib(n));
}

At least D isn't locking up beyond 12 tasks; looking at you, stdlib-nim. :)


More information about the Digitalmars-d-learn mailing list