multithreading - Semantic Issue "Attempt to use a deleted function" met compiling c++ code with std::thread usage -


i'm compiling block of code contains

std::thread::thread(fp fp&&__, args &&...__args)

function that, described in documentation c++ reference, performs following:

(2) initialization constructor construct thread object represents new joinable thread of execution. new thread of execution calls fn passing args arguments (using decay copies of lvalue or rvalue references). completion of construction synchronizes beginning of invocation of copy of fn.

i suppose means "the thread execute function fn after constructed".

however meet semantic issue during compile time, saying "attempt use deleted function" in library source file thread @ following line:

    __invoke(_vstd::move(_vstd::get<0>(__t)), _vstd::move(_vstd::get<_indices>(__t))...); 

i'm using llvm c++ std library c++ 11 support on xcode, mac os. know std::thread class c++ 11 feature , won't work on c++ 98. suggestions making code compilable? pointing out of bad use of c++ functions or classes appreciated.

my code trying perform timerthreadtask each time port event received. timerthreadtask perform callbackfunc after given sleep length, not if next port event happens before sleep times out:

#include <iostream> #include <thread> #include "unistd.h"  using namespace std; thread *timerthread; bool interrupted = false;  void callbackfunc(int anyparam) {     // perform timeout handling     cout << "callback handling parameter input " << anyparam << endl; }  void timerthreadtask(int sleeplengthinmillisec, void *callbackfuncptr(int anyparam)) {     // thread procedures     int counter = 100;     int sleepintervals = sleeplengthinmillisec / counter;     while (counter-- > 0) {         if (interrupted == true) { // interrupted             cout << "sleep interrupted because new port event received." << endl;             interrupted = false;   // kill thread             delete timerthread;             timerthread = null;             return;         }         usleep(sleepintervals);     }     callbackfuncptr(10);   // timeout, execute callback }  void onporteventreceived() {     // if message received in time, thread     // still executing. timer     // restarted.     if (timerthread != null) {         interrupted = true;     }     int sleeplengthinmillisec = 1000; // set timer     // starts timer thread (**** when line commented, compile success surely meaningless)     timerthread = new thread(timerthreadtask, sleeplengthinmillisec, callbackfunc); } 

void timerthreadtask(int sleeplengthinmillisec, void (*callbackfuncptr)(int anyparam)) //                                                   ^                ^ 

without parentheses, void *callbackfuncptr(int anyparam) function type (function taking int , returning void *) transformed function pointer type in function's parameter list, wrong return type (void * instead of void).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -