title: Why can JNI libraries compiled using OpenMP only be called on Java's "main" thread?
body: <p>I have written a library in C using a variety of the #pragma omp directives to parallelize execution. I am on Mac OS X 10.6. I have then wrapped these functions in a JNI library and called them from my Java application. </p>
  
  <p>It seems that calls to native functions containing OpenMP directives crash with EXC_BAD_ACCCESS if they are called from a Java thread besides the main one - in other words,</p>
  
  <pre><code>public static void main(String[] args) { nativeCall(); }
  </code></pre>
  
  <p>works, but calling the library on another thread, say the EventQueue</p>
  
  <pre><code>    public static void main(String[] args) { 
           SwingUtilities.invokeLater(
               new Runnable(){
                  public void run() { nativeCall(); }
  });}
  </code></pre>
  
  <p>crashes with EXC_BAD_ACCESS. </p>
  
  <p>I am a newcomer to OpenMP so I am not sure what could be causing this. What is special about the java "main" thread? Does it run in some privileged mode such that only it can access the resources necessary to initialize OpenMP parallelization tasks? I am also not intimately familiar with the inner workings of the JVM on OS X so I am not sure what the relationship between Java threads and native threads is.</p>
  
  <p>Any help is appreciated!</p>