[C++]getting segmentation fault while trying to call a function in the start routine of pthread_create

Hi All,
I am working on a benchmark application and trying to make it multi threaded.
I have spawned threads from a function called by main(). The start routine for the threads is a method in a different class.
The problem is: the thread which is created is able to get to the start routine but is not able to call another function of the same class. Segmentation fault is occurring at that point.

Here is the relevant snippet of the code:

extern "c"
{
void* run(void* arg)
{
CFileOp* trans = static_cast<CFileOp*>(arg);
trans->write_block(arg);
return 0;
}
}
// CFileOp is the class which contains the start routine(write_block) for the spawned threads as well as the method(my_write) which is getting called from the same start routine
//TestFileOps is a function called by main()
int
TestFileOps(int file_size, CGlobalItems &globals)
{
for(i =0;i<NTHREADS;i++){
pthread_create( &thread_id[i], NULL, run, buf);}

}
void* CFileOp::write_block(PVOID buf)
{
//some code

int rc = my_write(m_fd[m_file_ind], buf, m_chunk_size); /*segmentation fault occurs here */

//some code

}
CFileOp::my_write(m_fd[m_file_ind], buf, m_chunk_size)
{
// some code
}


Why is this segmentation fault occuring? Please let me know if my question isn't clear.
Any help would be greatly appreciated !
1
2
3
4
5
6
7
8
extern "c"
{
	void* run(void* arg)
	{
		CFileOp* trans = static_cast<CFileOp*>(arg); //??
		trans->write_block(arg); //????
		return 0;
}


So arg serves both as a pointer to a CFileOP object AND as a pointer to a buffer.
Sounds like something which is going to blowup in your face.
Or am I misreading your post/intentions?
Topic archived. No new replies allowed.