Ich würde gerne pthreads in C++ verwenden, habe aber Probleme mit der Definition der Funktionen, welche von pthread_create() aufgerufen werden sollen:
Beispiel:
pthread.cpp:
Code: Select all
#include <iostream.h>
#include <unistd.h>
#include <pthread.h>
class Test{
private:
void *do_something_else(void *arg);
public:
void do_something();
};
void Test::do_something(){
pthread_t thread1;
pthread_create(&thread1, NULL, do_something_else, NULL);
sleep(20);
pthread_kill(thread1, SIGTERM);
}
void *Test::do_something_else(void *arg){
while(1){
cout << "thread sleeps...\n";
sleep(3);
}
}
Code: Select all
g++ -Wno-deprecated pthread.cpp
pthread.cpp: In member function `void Test::do_something()':
pthread.cpp:17: error: argument of type `void*(Test::)(void*)' does not match `void*(*)(void*)'
Code: Select all
void *Test::do_something_else(void *arg){
...
}