#include "ThreadPool.h" //#include "threadpool.h" #include using namespace std; const int MAX_TASKS = 15; void hello(void* arg) { int* x = (int*) arg; cout << "Hello " << *x << endl; // cout << "\n"; } int main(int argc, char* argv[]) { ThreadPool tp(2); int ret = tp.init(); if (ret == -1) { std::cerr << "Failed to initialize thread pool!" << std::endl; return 0; } for (int i = 0; i < MAX_TASKS; i++) { int* x = new int(); *x = i+1; Task* t = new Task(&hello, (void*) x); // cout << "Adding to pool, task " << i+1 << endl; tp.addTask(t); // cout << "Added to pool, task " << i+1 << endl; } sleep(2); tp.destroy(); // TODO: delete worker objects std::cout << "Exiting app..." << std::endl; return 0; }