www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why does scopedTask increase memory consumption?

import core.thread;
import std.parallelism;
import std.stdio;

enum loops = 100;

void runTask()
    static void test() { }
    auto newTask = scopedTask(&test);

void main()
    foreach (_; 0 .. loops)


Running this consumes 8.024 KB on a win32 quad-core machine. If I set
loops to 100_000, it consumes 9.040 KB. I know each thread has its own
storage, but I'm invoking only one thread at a time, so after that
thread finishes I would assume the thread would clean up after itself
and release all memory.

In another app using scopedTask keeps eating more and more memory,
even though calling the same target function serially doesn't increase
memory consumption.

I admit I'm very new to concurrency so I don't know whether this is
normal or not. I know each thread has its own TLS but afaik when a
thread dies it should release those resources.
Nov 21 2011