title: How do I return a value from thread function?
body: <p>I have a struct like this:</p>
  
  <pre><code>struct data{
      int x;
      int y;
  }
  </code></pre>
  
  <p>and I have a thread function that looks like this:</p>
  
  <pre><code>void *threadFunction(void *item){
      data *myData = (data*) item;
      int first = 50;
      int second = 10;
      myData-&gt;x = first;
      myData-&gt;y = second;
      return(void*) myData;
  }
  </code></pre>
  
  <p>I call the thread function like this in main():</p>
  
  <pre><code>pthread_create(threadID, NULL, threadFunction, &amp;item);
  </code></pre>
  
  <p>but when I want to get the values from my thread function back into main() using this:</p>
  
  <pre><code>struct data* returnedItem;
  pthread_join(threadID, (void**) returnedItem;
  cout &lt;&lt; returnedItem-&gt;x &lt;&lt; returnedItem-&gt;y;
  </code></pre>
  
  <p>I'm not sure what happens as my program seems to just do nothing. It compiles and runs, but it loops infinitely somewhere or just waits on something. I'm not sure what happens at all, I just don't get any sort of response. What am I doing wrong? Is there something I'm missing in main() to retrieve the value from the pthread_join statement? Maybe I screwed up the arguments in the statement?  </p>