A Tid representing the new logical thread.
Notes: args must not have unshared aliasing. In other words, all arguments to fn must either be shared or immutable or have no pointer indirection. This is necessary for enforcing isolation among threads.
static void f(Tid self, string msg) { assert(msg == "Hello World"); } auto tid = spawn(&f, "Hello World");
Fails: char[] has mutable aliasing.
string msg = "Hello, World!"; static void f1(Tid self, string msg) {} static assert(!__traits(compiles, spawn(&f1, msg.dup))); static assert( __traits(compiles, spawn(&f1, msg.idup))); static void f2(Tid self, char[] msg) {} static assert(!__traits(compiles, spawn(&f2, msg.dup))); static assert(!__traits(compiles, spawn(&f2, msg.idup)));
New thread with anonymous function
auto self = thisTid(); spawn((Tid self, Tid caller) { caller.send("This is so great!"); }, self); assert(self.receiveOnly!string == "This is so great!");
Starts fn(args) in a new logical thread.
Executes the supplied function in a new logical thread represented by Tid.