change the structure a bit

This commit is contained in:
2022-09-28 19:53:31 +02:00
parent fe8e9715ac
commit dd62bfc010
8 changed files with 7 additions and 13 deletions

View File

@ -0,0 +1,31 @@
#include <iostream>
#include <thread>
using namespace std;
class MyExecutableObject {
public:
MyExecutableObject(uint32_t delayMs): delayMs(delayMs) {}
static void executeTask(MyExecutableObject& self) {
while(true) {
self.performOperation();
this_thread::sleep_for(std::chrono::milliseconds(self.delayMs));
}
}
void performOperation() {
cout << "Hello World" << endl;
}
private:
uint32_t delayMs;
};
int main() {
MyExecutableObject myExecutableObject(1000);
std::thread thread(
MyExecutableObject::executeTask,
std::reference_wrapper(myExecutableObject));
thread.join();
return 0;
}