我现在有一个函数需要执行,但是这个函数执行很耗时,我有时候想要在它执行过程中中止它的执行,这种功能应该怎么实现?类似软件执行中有进度条,然后它可以取消回退到没执行之前的状态。
#include<iostream>
using namespace std;
#include<Windows.h>
class testClass {
public:
void myfunction(int& a)
{
Sleep(100000); // 假如这个函数执行完会消耗100s
}
void stop() {
// ?
}
};
int main()
{
testClass tc;
int re = 10;
tc.myfunction(re); // 在它运行过程中怎么调用tc的stop函数中止它的运行?
return 0;
}