continue workshop
This commit is contained in:
17
start/tasks-srcs/main-01.cpp
Normal file
17
start/tasks-srcs/main-01.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void mySimpleTask() {
|
||||
using namespace std::chrono_literals;
|
||||
while(true) {
|
||||
cout << "Hello World" << endl;
|
||||
this_thread::sleep_for(1000ms);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::thread thread(mySimpleTask);
|
||||
thread.join();
|
||||
}
|
31
start/tasks-srcs/main-02.cpp
Normal file
31
start/tasks-srcs/main-02.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user