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);}
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?