On Wed, 24 Feb 2010 04:15:03 -0500, Norbert Nemec
<[email protected]> wrote:
Hi there,
I just found that recent change in the language to make all global
variables thread-local by default. This makes me think of a major
performance problem: every thread creation will have to copy all the
thread-local variables. This makes it impossible to efficiently spawn
many light-weight threads even if they do not make use of the global
variables at all.
I guess I am not the first one to spot this problem? I believe that
thread creation should come with as little overhead as possible. Maybe a
concept of light-weight threads based on side-effect free code could
complement the regular threads?
Just a quick idea to throw into discussion...
Greetings,
Norbert
Norbert, you are confusing threads with fibers. OS Threads have never
been, nor will ever be, "light-weight" in any sense of the word. If they
were, no one would care about thread-pools and the like. Languages that
feature light-weight threads, such as Erlang, are actually spawning
fibers. The Erlang runtime, for example, only ever uses one D style thread
to host millions of 'logical' threads.
Basic fiber support is already in druntime. Actually, it looks like the
std.thread and std.concurrency updates will internally use either a thread
pool or a fiber based back-end, so you might not have to worry about it.
If you're simply looking for a task library, dsimcha has been working on
one as have others (look in scrapple and for the blip project on dsource,
IIRC)