title: Share Barrier across threads in D
body: <p>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:</p>
  
  <pre class="lang-d prettyprint-override"><code>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(&amp;the_thread);
      }
      thread_joinAll();
  }
  </code></pre>
  
  <p>I've tried defining the barrier completely in the main function, but dmd complains:</p>
  
  <pre><code>static assert  "Aliases to mutable thread-local data not allowed."
  </code></pre>
  
  <p>I've also tried passing it as a shared variable and I get this:</p>
  
  <pre><code>non-shared method core.sync.barrier.Barrier.wait is not callable using a shared object
  </code></pre>