title: Encapsulating Threads creates problems
body: <p>I have the following encapsulation for my <code>pthread_t</code> threads:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  
  class Thread
  {
  public:
    void         run(const int);
    static void  *run_helper(void *);
    bool         startThread(int);
    void         joinThread();
  
    pthread_t     th;      
  };
  </code></pre>
  
  <p>Where <code>run</code> is my thread routine, and <code>run_helper</code> is the following:</p>
  
  <pre><code>void     *Thread::run_helper(int num)
  {
    return (Thread *)this-&gt;run(num);
  }
  </code></pre>
  
  <p>I start my threads like such:</p>
  
  <pre><code>bool    Thread::startThread(intptr_t arg)
  {
    return (pthread_create(&amp;this-&gt;th, NULL, &amp;run_helper(arg), (void *)(intptr_t)arg));
  }
  </code></pre>
  
  <p>But when I compile, I get the following errors:</p>
  
  <blockquote>
    <p>error: lvalue required as unary ‘&amp;’ operand
       return (pthread_create(&amp;this->th, NULL, &amp;run_helper(arg), (void *)(intptr_t)arg));</p>
    
    <p>error: ‘this’ is unavailable for static member functions
       return (Thread *)this->run(num);</p>
  </blockquote>
  
  <p>And despite trying, I can't seem to make this encapsulation work.</p>