Message from C, C++ talks

July 2019

— Also some sort of signaling would do it, but what would be the best way to do this in C++, I think that my way is a bit C'ish

Message permanent page

— If I were to do so I would calculate time till next event and sleep till that, but what's the c++ way ... Idk

Message permanent page

— Nothing wrong with it being "C'ish"

— And if you want to time it precisely you'd be using std::chrono

— 

I was also thinking about something like a function that takes the function pointer and then launches a new thread which sleeps until the given time and always calls that function

— But why do you need to run diffrent functions with n interval?

— How do you differentiate the code being c'ish or c++?

— I guess he wants to avoid function pointers

— But i don't see why and there's std::function

— It is a kind of a surveillance program lol, take screenshot at a user-defined interval, send logs to server every n minutes etc

Message permanent page

— Using stl versus not using it

— 

void timer_start(std::function<void(void)> func, unsigned int interval)
{
std::thread([func, interval]()
{
while (true)
{
auto x = std::chrono::steady_clock::now() + std::chrono::milliseconds(interval);
func();
std::this_thread::sleep_until(x);
}
}).detach();
}


I found this from internet, it looks pretty good, just have to figure out how to end/change the interval of already-made periodic function call

Message permanent page

— Mmm malware

— Not really

— I'm not writing a virus