c++ - Instantiate threads without running them? -


enableprint = (bool)someargv; //set via argv in code, don't worry  if (enableprint) {     std::thread printert(&printer, 1000);} //some code stuff if (enableprint) {     printert.join();} 

produces:

compile error 194:9: error: ‘printert’ not declared in scope printert.join();}

i'm aware caused c++ requirement declare printert outside of if block, don't know how how declare printert without causing automatically execute function code in thread? want able make running of printer function contingent on whether it's enabled or not.

std::thread has operator = trick. moves running thread thread variable.

the default constructor create std::thread variable isn't thread.

try like:

enableprint = (bool)someargv; //set via argv in code, don't worry  std::thread printert; if (enableprint) {     printert = std::thread(&printer, 1000);}  //some code stuff if (enableprint) {     printert.join();} 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -