title: Simultaneous CGAL calculations in multiple threads
body: <p>I'm trying to run multiple geometric calculations with CGAL simultaneously in multiple threads. All threads are 100% "isolated" from each other. Nevertheless the app crashes with an access violation:</p>
  
  <p><a href="http://s8.postimg.org/52u9qphdx/error.png" rel="nofollow">http://s8.postimg.org/52u9qphdx/error.png</a></p>
  
  <p>I've build a small example app to reproduce the error:</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;fstream&gt;
  #include "windows.h"
  #include "cTestClass.h"
  
  int main ( int argc, char *argv[] ){
  
      cTestClass *eval0 = new cTestClass("d://.partion_2.stl", 0);
      cTestClass *eval1 = new cTestClass("d://.partion_2.stl", 1);
  
      eval0-&gt;start_eval();
      eval1-&gt;start_eval();
  
      while (!eval0-&gt;eval_finished())
      {
         Sleep(200);
      }
      while (!eval1-&gt;eval_finished())
      {
         Sleep(200);
      }
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p><strong>cTestClass.h</strong></p>
  
  <pre><code>#ifndef CTEST_CLASS_H
  #define CTEST_CLASS_H
  
  #include &lt;atomic&gt;
  #include &lt;thread&gt;
  
  class cTestClass
  {
  private:
      std::atomic&lt;bool&gt; flag_eval_finished;
      std::thread eval_thread;
      std::string stl_file_name;
      unsigned int thread_index;
  
      cTestClass(){ }
      void evaluate_partition();
  
  public:
      cTestClass(std::string argStlFile, unsigned int argThread_index);
      void start_eval();
      bool eval_finished(); 
  };
  
  #endif
  </code></pre>
  
  <p><strong>cTestClass.cpp</strong></p>
  
  <pre><code>#include "cTestClass.h"
  
  #include &lt;CGAL/Exact_predicates_exact_constructions_kernel.h&gt;
  #include &lt;CGAL/Polyhedron_3.h&gt;
  #include &lt;CGAL/Nef_polyhedron_3.h&gt;
  #include &lt;CGAL/polygon_soup_to_polyhedron_3.h&gt;
  #include &lt;CGAL/IO/Polyhedron_builder_from_STL.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  //typedef CGAL::Cartesian&lt;double&gt; Kernel;
  typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
  typedef CGAL::Polyhedron_3&lt;Kernel&gt; Polyhedron_3;
  typedef CGAL::Nef_polyhedron_3&lt;Kernel&gt;  Nef_polyhedron_3;
  typedef CGAL::Point_3&lt;Kernel&gt; Point_3;
  
  //typedef Polyhedron::Point_iterator Point_iterator;
  typedef Polyhedron_3::Vertex_iterator Vertex_iterator;
  typedef Polyhedron_3::Facet_iterator Facet_iterator;
  typedef Polyhedron_3::Halfedge_around_facet_circulator Halfedge_facet_circulator;
  typedef Nef_polyhedron_3::Volume_const_iterator Volume_const_iterator;
  typedef Kernel::Iso_cuboid_3 Iso_cuboid;
  
  //constructor
  cTestClass::cTestClass(std::string argStlFile, unsigned int argThread_index)
  {
      thread_index = argThread_index;
      stl_file_name = argStlFile;
      flag_eval_finished = false;
  }
  
  //===========================================================================================
  // public member functions
  void cTestClass::start_eval()
  {
      std::cout &lt;&lt; "Thread " &lt;&lt; thread_index &lt;&lt; ": start" &lt;&lt; std::endl;
      eval_thread = std::thread(&amp;cTestClass::evaluate_partition, this);
  }
  
  bool cTestClass::eval_finished()
  {
      return flag_eval_finished;
  }
  
  //===========================================================================================
  //private member functions
  void cTestClass::evaluate_partition()
  {
  
      //read stl file and create cgal polyhedron
      Polyhedron_3 poly_Partition; 
      std::ifstream stl_file(stl_file_name.c_str(), std::ifstream::in);
      std::vector&lt;CGAL::cpp11::array&lt;double, 3&gt; &gt; points;
      std::vector&lt;CGAL::cpp11::array&lt;int, 3&gt; &gt; triangles;
      CGAL::read_STL(stl_file, points, triangles);
      stl_file.close();
  
      //create polyhedron
      CGAL::polygon_soup_to_polyhedron_3(poly_Partition, points, triangles);
  
  
      //convert polyhedron to nef_poly representation
      std::cout &lt;&lt; "Thread " &lt;&lt; thread_index &lt;&lt; ": " &lt;&lt;"Converting partition polyhedron to Nef representation" &lt;&lt; std::endl;
      Nef_polyhedron_3 nefpoly_Partition(poly_Partition);
  
      flag_eval_finished = true;
  }
  </code></pre>
  
  <p>Anyone got an idea what causes this crash?</p>
  
  <p>Best regards</p>
  
  <p>Monchi</p>