quote:Original post by fredizzimo
Declare Printmess as static.
Ok so i declared it as follows:
static void *Printmess(void*);
and the programs runs fine until it hits:
rc = pthread_create(&trad[t], NULL, test.Printmess, (void *)t);
And there it recieves segmentation fault.
Well here is the updated code:
#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <iostream>#include <cstdlib>#include <pthread.h>using namespace std;class CTest{ public: static void *Printmess(void*);};void *CTest:rintmess(void *id){ cout << id << ":Hello World!" << endl; pthread_exit(NULL);}int main(int argc, char *argv[]){ CTest test; pthread_t trad[5]; int rc, t; for(t=0;t<5;t++){ cout << "Creating thread..." << t << endl; rc = pthread_create(&trad[t], NULL, test.Printmess, (void *)t); if(rc){ cout << "Could not create thread!" << endl; return -1; } } pthread_exit(NULL); return 0; }