54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "pip.h"
|
|
#include "pithreadpoolexecutor.h"
|
|
|
|
class A: public PIObject {
|
|
PIOBJECT(A)
|
|
|
|
public:
|
|
A(PIString n = {}) { setName(n); }
|
|
void foo() {
|
|
100_ms .sleep();
|
|
piCoutObj << "foo!";
|
|
100_ms .sleep();
|
|
}
|
|
};
|
|
|
|
int main(int argc, char * argv[]) {
|
|
PIVector<A *> objects;
|
|
objects << new A("1") << new A("2") << new A("3");
|
|
|
|
PITimer status_timer;
|
|
PIThreadPoolWorker pool(2);
|
|
pool.start();
|
|
|
|
// int64_t id = -1;
|
|
// status_timer.start(10_Hz, [&id, &pool] { piCout << "[timer] status" << (int)pool.taskStatus(id); });
|
|
|
|
100_ms .sleep();
|
|
// pool.enqueueTask([](int64_t id) {
|
|
// piCout << "[task ] start, id" << id;
|
|
// // 500_ms .sleep();
|
|
// piCout << "[task ] done";
|
|
// });
|
|
pool.enqueueTask(objects[0], &A::foo);
|
|
pool.enqueueTask(objects[1], &A::foo);
|
|
pool.enqueueTask(objects[1], &A::foo);
|
|
pool.enqueueTask(objects[2], &A::foo);
|
|
|
|
10_ms .sleep();
|
|
delete objects[1];
|
|
objects.remove(1);
|
|
// piCout << "[main ]" << "enqueued, id" << id;
|
|
|
|
// 200_ms .sleep();
|
|
piCout << "[main ]" << "wait ...";
|
|
piCout << "[main ]" << "wait done";
|
|
|
|
1000_ms .sleep();
|
|
|
|
pool.stopAndWait();
|
|
status_timer.stopAndWait();
|
|
piDeleteAll(objects);
|
|
return 0;
|
|
}
|