Completely new to threading and concurrency but I'm trying to start a function as a new thread and I don't understand my errors. I receive an error along the lines of Candidate expects X arguments, 2 provided
. This error repeats for 0 < X <= 9
(except 2). However, in every example I've seen it's as simple as just putting your function and it's arguments. My code looks like:
Trainer.cpp:
int time = 5; // for example
void Member::decrement(int seconds){
while(seconds > 0){
seconds--;
Sleep(1000);
}
isBusy = false;
}
void Member::startDecrement(string state){
if (state == "busy"){ // isBusy is a private boolean, hence this
isBusy = true;
thread myThread = thread(decrement, time); // Thread for method
myThread.join();
else {
isBusy = false;
}
}
Yet this doesn't work? Can somebody give me guidance on this please, what I'm trying to do is quite simple but I have found no way that works for me as of yet. Alternatives to thread
are appreciated too, I've seen that std::async
is an option but that doesn't seem to work with my compiler setup.
Setup info: -sdt=c++11
, MinGW
, Win64
, GCC 4.7.2
EDIT:
Seeing as I've been nailed for errors, here is the entire error log.
I've also tried the code provided in the answer, no luck.