multithreading - C++ freeRTOS Task, invalid use of non-static member function -




where problem?

void myclass::task(void *pvparameter){      while(1){          this->update();      } }  void myclass::starttask(){     xtaskcreate(this->task, "task", 2048, null, 5, null); } 

but, this:

error: invalid use of non-static member function

i cannot find useful doc check mistake,
think should like: (c++11's std::thread) e.g.:

xtaskcreate(&myclass::task, "task", 2048, (void*)this, 5, null); 

solution works me:

void myclass::task(){     while(1){         this->update();     } }  static void myclass::starttaskimpl(void* _this){     static_cast<myclass*>(_this)->task(); }  void myclass::starttask(){     xtaskcreate(this->starttaskimpl, "task", 2048, this, 5, null); } 

i use pattern wrapper function instanciating pthread non-static member functions. function called in xtask static member function, calling task function using void* pointer. myclass.hpp :

class myclass {     public:         myclass() {}         ~myclass() {}     private:         void update();         void task();         static void starttaskimpl(void*);         void starttask();  } 

myclass.cpp :

void myclass::task(){      while(1){          this->update();      } }  void myclass::starttaskimpl(void* _this){     (myclass*)_this->task(); } void myclass::starttask(){     xtaskcreate(this->starttaskimpl, "task", 2048, this, 5, null); } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -