#include #include #include #include "threadpool.h" #include "threadpool.cpp" #include "TaskQueue.h" void taskFunc(void* arg) { size_t num = *static_cast(arg); std::cout << "thread id: " << std::to_string(pthread_self()) << " is working, the arg(num) = " << num << std::endl; sleep(1); } int main() { printf("%s 向你问好!\n", "threadpool_cpp"); // 创建线程池 ThreadPool pool = ThreadPool(3, 10); for (size_t i = 0; i < 100; i++) { size_t* num = new size_t(i + 100); pool.addTask(Task(taskFunc, num)); } sleep(20); return 0; }