I'm having a heck of a time trying to get the barrier sync in D to work properly. I'm currently not getting any compiler errors, however every time it reaches the barrier I get a segmentation fault. Here's basically what I have:
import std.stdio;
import std.conv;
import std.concurrency;
import core.thread;
import core.sync.barrier;
//create barrier
Barrier barrier;
void the_thread()
{
barrier.wait(); //I get a segmentation fault here
}
void main(string[] args)
{
int threads = to!int(args[1]); //number of threads
//init barrier
barrier = new Barrier(threads);
//launch threads
foreach(i; 0 .. threads)
{
spawn(&the_thread);
}
thread_joinAll();
}
I've tried defining the barrier completely in the main function, but dmd complains:
static assert "Aliases to mutable thread-local data not allowed."
I've also tried passing it as a shared variable and I get this:
non-shared method core.sync.barrier.Barrier.wait is not callable using a shared object