On Sat, 10 Jan 2015 19:50:06 GMT, Jack Applegame wrote:
You can use vibe.core.concurrency.
This is definitely the best approach for sending from the worker thread to the vibe.d thread. The other way around will be problematic though, unless you are starting an event loop there and run the workload within a task:
__gshared Task workertask, maintask;
static this()
{
maintask = runTask({
auto msg = receiveOnly!int;
assert(msg == 1);
send(workertask, 2);
});
auto th = new Thread({
workertask = runTask({
// send some message
send(maintask, 1);
// perform work
// receive some message
auto resp = receiveOnly!int();
assert(resp == 2);
});
runEventLoop();
});
th.start();
}
runWorkerTaskH
might be a vible alternative using the integrated thread pool:
__gshared Task workertask, maintask;
static this()
{
maintask = runTask({
auto msg = receiveOnly!int;
assert(msg == 1);
send(workertask, 2);
});
workertask = runWorkerTaskH({
// send some message
send(maintask, 1);
// perform work
// receive some message
auto resp = receiveOnly!int();
assert(resp == 2);
});
}
The next version of DMD will include a plug-in API to integrate vibe.d with std.concurrency
, so that it can also be used. However, there are still some shortcomings (e.g. only spawn
vs. runTask
and runWorkerTask
for vibe.core.concurrency
).