initial commit

This commit is contained in:
Erik Bročko 2022-05-29 22:38:43 +02:00
parent 7060ffa3bb
commit fba3816b37
Signed by: ericek111
GPG Key ID: 414DED726771329C

View File

@ -1,21 +1,37 @@
#include <iostream>
#include <MyThreadPool.h> #include <MyThreadPool.h>
#include <iostream>
int main() { int main()
{
MyThreadPool::ThreadPool tp(4); MyThreadPool::ThreadPool tp(4);
auto task = [](int i) { auto task = [](int i) {
std::cout << "Test " << i << "\n"; std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Testing future " << i << std::endl;
return i / 2; 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); auto fut = tp.enqueue(0, task, 10);
std::cout << "Returned: " << fut.get() << std::endl;
tp.waitForTasks(); tp.waitForTasks();
// std::cout << "All: " << fut.get() << std::endl;
std::cout << "Done." << std::endl; 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; return 0;
} }