c++后台更新

C++ background update

本文关键字:更新 后台 c++      更新时间:2023-10-16

如何在后台调用更新函数?我需要每5秒更新一次集合

在c#中,我创建了定时器set start stop and delegate,它可以工作。

在c++中是否存在?

c++ 11:

#include <thread>
void update() {
    for (;;) {
        do_update();
        this_thread::sleep_for(std::chrono::seconds(5));
    }
}
int main() {
    std::thread thr(update);
    thr.detach();
    // do whatever the program needs to do
    return 0;
}

在我们的嵌入式系统上,我们创建了一个在后台运行的单独任务。另一种方法是通过中断完成大部分工作,非中断代码将在后台运行。

我猜这是平台相关的,你用的是哪个平台?