//#include #include #include #include #include #include "thread_pool.h" void taskFunc(void* arg) { int num = *(int*)arg; printf("thread id: %lu is working, the arg(num)=%d\n", pthread_self(), num); sleep(1); } int main() { printf("%s 向你问好!\n", "threadpool"); // 创建出一个线程池 ThreadPool* pool = threadPoolCreate(3, 10, 100); // 添加任务 for (size_t i = 0; i < 100; i++) { int* num = (int*)malloc(sizeof(int)); *num = (int)i + 100; threadPoolAddTask(pool, taskFunc, num); } //sleep(50); int busyNum = getWorkingThreads(pool); int taskNum = getTaskNum(pool); while (1) { printf("\t\tget alive thread: %d\n", getALiveThreads(pool)); printf("\t\tbusyNum: %d\n", busyNum); taskNum = getTaskNum(pool); printf("\t\ttaskNum: %d\n", taskNum); sleep(1); if (taskNum == 0) { break; } } sleep(10); threadPoolDestroy(pool); return 0; }