here's how i do it in C++:
Code:
#include <iostream>
#include <pthread.h>
using namespace std;
void* callback(void* obj);
class Thread {
public:
int main()
{
cout << "Hi there" << endl;
return(0);
}
void run()
{
pthread_create(&thread, 0, &callback, this);
}
pthread_t thread;
}; // class Thread
void* callback(void* obj)
{
static_cast<Thread*>(obj)->main();
return(0);
} // callback
int main()
{
Thread thread;
thread.run();
return(0);
} // main()
remember to link with pthread, or you'll get "mysterious" SIGSEGVs
Code:
g++ -g -Wall -l pthread my_program.cpp -o my_program
edit:
then you add the class `Thread' as a superclass of your class, and define a method `main' for it
Bookmarks