title: How can I call the GLib threads g_thread_init using JNA?
body: <p>I'm trying to invoke a function in a native C library using JNA which uses GLib and GLib Threads.  When I attempt to invoke the function, the JVM crashes and the following error is printed:</p>
  
  <pre><code>GLib-ERROR **: The thread system is not yet initialized. 
  aborting...
  </code></pre>
  
  <p>I'm pretty sure that means the code needs to invoke the <code>g_thread_init</code> function in the <code>gthread</code> library before invoking the target function. Thus, I defined the following interface to load the <code>gthread</code> library...</p>
  
  <pre><code>public interface GLibThreads extends Library {
  
      public static final GLibThreads INSTANCE = 
                (GLibThreads) Native.loadLibrary("gthread-2.0", GLibThreads.class);
  
      public void g_thread_init(Pointer pointer);
  
  }
  </code></pre>
  
  <p>...and I tried invoking it before the target function...</p>
  
  <pre><code>NativeLibrary.getInstance("glib-2.0");
  
  GLibThreads.INSTANCE.g_thread_init(Pointer.NULL);
  String flavors = LibSoda.INSTANCE.getFlavors();
  </code></pre>
  
  <p>...but unfortunately, this doesn't work. I still get the "thread system is not yet initialized" error.</p>
  
  <p>I thought my problem might have been related to defining the method to take a JNA <code>Pointer</code>. Here's how the <code>g_thread_init</code> function is defined in the gthread header:</p>
  
  <pre><code>void    g_thread_init   (GThreadFunctions       *vtable);
  </code></pre>
  
  <p>So I tried defining the <code>GThreadFunctions</code> struct and passing in <code>null</code>. Unfortunately, that didn't make any difference, and I still get the "thread system is not yet initialized" error.</p>
  
  <p>How can I initialize the threading system so I can successfully invoke the target function?</p>