module z; import std.stdio; import std.concurrency; import core.thread; import std.variant; private struct Exit{}; private struct supervisorAnswer { Variant ret; } private __gshared Tid supervisorTid; private void supervisor() { static Variant[string] zval; bool done = false; void _store(T)(string k, T v) { assert(k.length > 0); zval[k] = v; } void _get(Tid id, string k) { id.send(supervisorAnswer(zval.get(k, Variant("NOTFOUND")))); } while (!done) { supervisorAnswer answer; receive( (Exit s) { done = true; }, &_store!long, &_store!ulong, &_store!int, &_store!uint, &_store!float, &_store!double, &_store!string, &_store!Variant, &_get, (Variant e) { writeln(e); }, ); } } Variant Get(const string s) { Variant r; supervisorTid.send(thisTid, s); writeln("TUQLUE"); receive( (supervisorAnswer a) => r = a.ret ); writeln("42"); return r; } void Set(T)(const string s, T v) { supervisorTid.send(s, v); } shared static this() { supervisorTid = spawn(&supervisor); } shared static ~this() { send(supervisorTid, Exit()); } void main() { Set("1", 11); writeln(Get("1")); send(supervisorTid, Exit()); thread_joinAll(); }