MobaXterm真是个好东西!
支持SSH,FTP,串口,VNC,X server等功能;
软件小巧强大,还有绿色版。
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
class Timer {
std::atomic<bool> active{false};
public:
void setTimeout(auto function, int delay);
void setInterval(auto function, int interval);
inline void stop(){ active = false; }
inline bool isActive() const { return active.load(); };
};
void Timer::setTimeout(auto function, int delay) {
active = true;
std::thread t([=]() {
if(!active.load()) return;
std::this_thread::sleep_for(std::chrono::milliseconds(delay));//std::chrono::minutes(5)
if(!active.load()) return;
function();
});
t.detach();
}
void Timer::setInterval(auto function, int interval) {
active = true;
std::thread t([=]() {
while(active.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
if(!active.load()) return;
function();
}
});
t.detach();
}
版权声明:本文为a379039233原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。