C++ and pthreads
Posted: Tue Jan 09, 2007 6:02 pm
Hello!
I have been trying to create multiple threads in a C++ program I am developing. Moreover, I plan to create a nice class to enclose pthreads. However, when trying to pass a member function (virtual, non-virtual) to pthread_create I always get this error:
A cut down version of the class:
And the Code:
I was reading about templates to solve the problem, but I think I am still stuck with it when I get down to pthread_create. I have also tried casting it to anything I could think of with no results ... Thanks!
I have been trying to create multiple threads in a C++ program I am developing. Moreover, I plan to create a nice class to enclose pthreads. However, when trying to pass a member function (virtual, non-virtual) to pthread_create I always get this error:
Code: Select all
mtkWindow.cc: In member function `void* mtkWindow::run()':
mtkWindow.cc:93: error: argument of type `void*(mtkWindow::)(void*)' does not
match `void*(*)(void*)'
Code: Select all
class mtkWindow : public mtkWidget {
private:
pthread_t thread;
void *thread_main(void *arg);
public:
void *run();
void main() {
pthread_join(thread, NULL);
}
};
Code: Select all
void *mtkWindow::run()
{
pthread_create(&thread, NULL, thread_main, (void*)this);
}
void *mtkWindow::thread_main(void *arg)
{
for(;;) {
///Do whatever...
}
}