I want to spawn a thread from within my class but can't seem to find the correct formula to make pthread_create()
happy.
My class looks like:
#ifndef _BFD_ENDPOINT_H_
#define _BFD_ENDPOINT_H_
#include <pthread.h>
using namespace std;
enum BfdState_e {
BFD_STAT_ADMIN_DOWN = 0,
BFD_STAT_DOWN,
BFD_STAT_INIT,
BFD_STAT_UP };
class BfdEndpoint {
public:
int RxIntvlSet(int);
int TxIntvlSet(int);
int MultSet(int);
int ActvSet(bool);
enum BfdState_e StatusGet();
BfdEndpoint(); // constructor
~BfdEndpoint(); // destructor
public:
//configuration params
int rx; // Rx interval [us]
int tx; // Tx interval [us]
int mult; // multiplier
bool active; // active (1) or passive (0) endpoint
//internal vars
enum BfdState_e status;
pthread_t *RxTh;
pthread_t *TxTh;
//internal methods
int Start();
void *RxSM(void);
void *TxSM(void);
};
#endif
and the implementation of the respective function looks like:
void *BfdEndpoint::RxSM(void)
{
return NULL;
}
int BfdEndpoint::Start(void)
{
int rv = 0;
rv = pthread_create(RxTh,NULL,&BfdEndpoint::RxSM,NULL);
}
and g++
is barking the following:
$ g++ *.cpp -o bfd
bfd.cpp: In member function ‘int BfdEndpoint::Start()’:
bfd.cpp:34:55: error: cannot convert ‘void* (BfdEndpoint::*)()’ to ‘void* (*)(void*)’ for argument ‘3’ to ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
rv = pthread_create(RxTh,NULL,&BfdEndpoint::RxSM,NULL);
How do I do this?