title: Configure check for threadsafe errno
body: <p>We had a problem report in our software that turned out to be caused by a non-threadsafe-<code>errno</code> (thanks to slightly wrong compiler flags on Solaris).</p>
  
  <p>I'd like to add a configure check to ensure that this bogus mode of operation doesn't sneak back in again.</p>
  
  <p>I started with something fairly naive:</p>
  
  <pre><code>#include &lt;errno.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;stdio.h&gt;
  
  void* thread1_func(void*)
  {
      errno = 1;
      return 0;
  }
  
  int
  main ()
  {
      errno = 0;
      pthread_t t1;
      pthread_create(&amp;t1, NULL, thread1_func, NULL);
      pthread_join(t1, NULL);
      return errno;
  }
  </code></pre>
  
  <p>This works well on most platforms, except on OpenBSD where <code>return errno</code> produces 2 - even though <code>pthread_create</code>/<code>pthread_join</code> don't touch <code>errno</code>. (Hilariously, this goes away if I insert a <code>printf</code> call before <code>pthread_create</code>, which made debugging this quite difficult.</p>
  
  <p>I suspect accessing <code>errno</code> in this manner is technically undefined.</p>
  
  <p>How can I check if <code>errno</code> is threadsafe?</p>