MyThreadPool/main.cpp

43 lines
1.0 KiB
C++
Raw Normal View History

2022-05-29 22:41:15 +02:00
#include <MyThreadPool.h>
#include <iostream>
2022-05-29 22:59:56 +02:00
#include <string>
2022-05-29 22:41:15 +02:00
2022-05-29 22:59:56 +02:00
int main(int argc, char* argv[])
2022-05-29 22:41:15 +02:00
{
2022-05-29 22:59:56 +02:00
size_t threadCount = 0;
if (argc > 1) {
threadCount = std::stoul(argv[1]);
}
MyThreadPool::ThreadPool tp(threadCount);
2022-05-29 22:41:15 +02:00
auto task = [](int i) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Testing future " << i << std::endl;
return i / 2;
};
tp.enqueue(
0, [](int i) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Test " << i << std::endl;
return i / 2;
},
45);
auto fut = tp.enqueue(0, task, 10);
std::cout << "Returned: " << fut.get() << std::endl;
tp.waitForTasks();
std::cout << "Done." << std::endl;
tp.enqueue(0, []() {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Finished with destructor." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
});
return 0;
}