xxxxxxxxxx
import std.stdio, std.datetime.stopwatch;
import std.concurrency;
import core.thread;
__gshared StopWatch sw;
void myThread ()
{
import core.time;
writeln(threadCount, "myThread started.");
Thread.sleep(2.seconds); // busy
writeln(threadCount, "myThread: ending.");
}
string threadCount()
{
import std.conv, std.algorithm, std.range;
return text(sw.peek.toString, "\t # total/running = ", Thread.getAll.length, "/", Thread.getAll.filter!(a => a.isRunning).array.length, ": ");
}
void main ()
{
sw.start;
writeln(threadCount, "main() started");
Tid thread = spawnLinked(& myThread);
writeln(threadCount, "spawned.");
receive((Variant v) {writeln(threadCount, "main() got message ", v);});
}