jeudi 23 juin 2016

wake up thread at specified time

I want to wake up my threads a specified time. Can I do it like this?

#include <chrono>
#include <thread>
using namespace std::literals::chrono_literals;
void foo() {}
int main()
{
    using clock = std::chrono::steady_clock;
    clock::time_point next_time_point = clock::now() + 20s;
    foo();
    std::this_thread::sleep_until(next_time_point);
}

Aucun commentaire:

Enregistrer un commentaire