On Wednesday, July 15, 2015 16:21:29 aki via Digitalmars-d-learn wrote: > I want to make sure about the semantics of unshared variables. > > import std.concurrency; > import core.thread; > ubyte[1024 * 1024] buf1MB; > void fun() { Thread.sleep(5000.msecs); } > void testThread() { > foreach(i; 0..2000) { > spawn(&fun); > } > } > > Are instances of buf1MB created for every threads? > Even if it is never accessed by the threads? > If some static variable is defined in other module > or in some library, all of them also instantiated > for every threads?
Yes. Every thread gets a copy of the non-shared static variables, and all of the non-shared static constructors get run for each thread. - Jonathan M Davis