The title says it all. Basically want to be able to activate a function at a certain time, but I want to do this without interrupting the user. Previously, I played with this idea using sleep_until:
cout << "set time" << endl;
cin >> time;
sleep_until (system_clock::from_time_t (timegm(&time)));
someFunction();
The problem is, the user can't do anything once sleep_until starts. What I want to happen is for the user to be able to continue doing things with the program uninterrupted and for the function to activate at the specified time. How would I go about doing this?
EDIT: To clarify, I want the user to do different things in my program until the time has come for the function to activate.
EDIT2: When trying to get the thread going:
In Schedule class:
void Schedule::timeAlert(tm time) {
sleep_until (system_clock::from_time_t (timegm(&time)));
cout << "It is " << std::asctime(&time);
}
In main:
Schedule mySchedule
std::thread t(mySchedule.timeAlert, time);
t.join();
EDIT3: I have tried this method too:
std::thread t(&Schedule::timeAlert, this, time1);
t.join();
But I get this problem...
error: invalid use of ‘this’ in non-member function
std::thread t(&Schedule::timeAlert, this, time1);
Despite timeAlert being in public under my .h file and being labeled with Schedule:: in my cpp file.