import std.stdio; import std.thread; import std.c.windows.windows; bool quit; int run(void* arg) { writefln("run.start"); try { while (!quit) { writef("+"); Sleep(10000); // thread is busy for a long time } } finally { // free some important resources... writefln("run.finally"); } writefln("run.end"); return 0; } void main() { writefln("main.start"); Thread thread = new Thread(&run, null); thread.start(); Sleep(1000); // main thread is doing something... writefln("main.requestQuit"); quit = true; //...we want to quit _now_! // thread.wait(); // would wait ~9 seconds // thread.wait(100); // would not release the resources writefln("main.end"); }