multiple threads-not able to access class member variables set by constructor
<p>I am spawning threads from one of the functions called by main. 
The start routine of this thread is a function in another separate class altogether. So to get access to that class, i have written an extern "C" function, by which i am able to call the start routine.
But the problem is, after getting to the start routine, the thread is not able to access the member variables value set by the constructor of the Class.</p>

<p>This seems strange to me as everything is perfect when i am running the code without using threads.
Can someone please suggest me what would be going wrong?</p>

<p>I am posting some relevant code details below:</p>

<p>`extern "C"{</p>

<pre><code>void* run(void* arg)
{
    CFileOp* trans = static_cast&lt;CFileOp*&gt;(arg);
    trans-&gt;write_block(arg);
    return 0;
}
</code></pre>

<p>}</p>

<pre><code>int
TestFileOps(int file_size, CGlobalItems &amp;globals){
...

for(i = 0; i &lt; num_chunks; i++)
{
pthread_create( &amp;thread_id[i], NULL, run, buf);
}

...
}`
</code></pre>

<p>//there is a class CFileOp which has some private member variables and write_block is a public function of it.</p>

<pre><code>void* CFileOp::write_block(PVOID buf)
{
int rc = my_write(78, buf, m_chunk_size);
 if(rc != m_chunk_size)
 {
   fprintf(stderr, "Can't write block; rc=%d, buf=%p, chunk_size=%d\n", rc, buf, m_chunk_size);
    pthread_exit((void *)-1);return 0;;
  }
m_cur_pos++;
fprintf(stderr,"m_cur_pos: %d   m_chunks_per_file: %d\t",m_cur_pos,m_chunks_per_file);
  if(m_cur_pos &gt;= m_chunks_per_file)                                                    
  {
   if(seek(0, SEEK_CUR) == -1)
    pthread_exit((void *)-1);return 0;// return -1;
 }
pthread_exit((void *)rc);
return 0;
}
</code></pre>

<p>I can't post the whole code as its a benchmark code and is very long and detailed. 
Please help.</p>
