My question is regarding the values passed in when creating an object. Making debugging, it is clear that the values of 'id', 'cont', 'size' and 'nthreads' get lost somehow. I searched the internet and found the link https://stackoverflow.com/questions/1151582 teaching how to pass an object and make a method call him. It works until the method 'run ()', where the values passed when creating the object are lost. I do not know if I need to mess with static types so that it does not, however, I am not knowing what to do.
class Section1SimpleBarrierThread {
Section1SimpleBarrierThread(int id, Section1Counter* cont, int size, int nthreads) {
this->id = id;
this->cont = cont;
this->size = size;
this->nthreads = nthreads;
}
void* run(void){
pthread_mutex_lock(&mutex);
for(int i=0; i<size; i++) {
cont->shared_cont++;
if(cont->shared_cont != this->nthreads) {
//cont.wait();
} else {
//cont->shared_cont = 0;
// cont.notifyAll();
}
}
pthread_mutex_unlock(&mutex);
}
static void* run_helper(void* context){
return ((Section1SimpleBarrierThread*)context)->run();
}
};
while ( (time < TARGETTIME) && (size < MAXSIZE) ){
j->resetTimer("Section1:Barrier:Simple"); j->startTimer("Section1:Barrier:Simple");
for(int i=0; i<nthreads; i++) {
thobjectsSimpleBarrierThread[i]= new Section1SimpleBarrierThread(i,cont,size,nthreads);
pthread_create(&thread_id[i],NULL,&Section1SimpleBarrierThread::run_helper,&thobjectsSimpleBarrierThread[i]);
for(int i=0; i<nthreads; i++) {
pthread_join(thread_id[i],NULL);
}
}