title: How to return a value from pthread threads in C?
body: <p>I'am new to C and would like to play with threads a bit. I would like to return some value from a thread using <code>pthread_exit()</code></p>
  <p>My code is as follows:</p>
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  
  void *myThread()
  {
     int ret = 42;
     pthread_exit(&amp;ret);
  }
  
  int main()
  {
     pthread_t tid;
     void *status;
   
     pthread_create(&amp;tid, NULL, myThread, NULL);
     pthread_join(tid, &amp;status);
  
     printf(&quot;%d\n&quot;,*(int*)status);   
   
     return 0;
  }
  </code></pre>
  <p>I would expect the program output <code>&quot;42\n&quot;</code> but it outputs a random number. How can I print the returned value?</p>
  <p>It seems to be a problem that I am returning a pointer to a local variable. What is the best practice of returning/storing variables of multiple threads? A global hash table?</p>