Creating an c++ object instance of class in every thread?

I have a boost multithreaded ga which works fine for running functions in parallel using multithreading to evaluate each function. I am using boost. However when I try to run an instance of a class (member function) it gives a memory dump and checks out after the first or second thread.

Here is a example of my code:

class topclass{
void thread_function(int *somedata);
}

class myclass{
void function(int var1,int var2,int var3);
}

void myclass::funct(int var .....

....

void topclass::thread_function(int *somedata){
myclass *example = new myclass;
example->funct(var1,var2,var3);
}

Is there something I should do to ensure multiple instances of the same class object dont have problems with memory?
(I am using boost threading and not pthreads which doesn't work with globals when used inside a class.)
The memory I am assigning to myclass object is done in funct. However I could also do it inside a creater function:

class myclass{
public:
int *globals;

myclass(int var1,int var2,int var3){
globals = new int[var1];

/*(.... assign memory etc)*/
}
};

void topclass::thread_function(int *somedata){
myclass example(var1,var2,var3);
}


Either way it seems to break down and produce a memory dump after the first or second thread. Please help.



Last edited on
Topic archived. No new replies allowed.