if (0) { /* 如果立即运行 acl_pthread_pool_destroy,则由于调用了线程池销毁函数, * 主线程便立刻通知空闲线程退出,所有空闲线程不必等待空闲超时时间便可退出, */ printf("> wait all threads to be idle and free thread pool\r\n"); /* 立即销毁线程池 */ acl_pthread_pool_destroy(thr_pool); } else { /* 因为不立即调用 acl_pthread_pool_destroy,所有所有空闲线程都是当空闲 * 超时时间到达后才退出 */ while (1) { int ret;
ret = acl_pthread_pool_size(thr_pool); if (ret == 0) break; printf("> current threads in thread pool is: %d\r\n", ret); sleep(1); } /* 线程池中的工作线程数为0时销毁线程池 */ printf("> all worker thread exit now\r\n"); acl_pthread_pool_destroy(thr_pool); }
/* 主线程等待用户在终端输入任意字符后退出 */ printf("> enter any key to exit\r\n"); getchar();
on_thread_init: thread(23012) init now thread start! tid=23012, i=0, __local=0 thread start! tid=23012, i=0, __local=1 > current threads in thread pool is: 2 on_thread_init: thread(23516) init now thread start! tid=23516, i=1, __local=0 thread start! tid=23516, i=1, __local=1 > current threads in thread pool is: 2 thread start! tid=23012, i=0, __local=2 thread start! tid=23516, i=1, __local=2 thread start! tid=23012, i=0, __local=3 > current threads in thread pool is: 2 thread start! tid=23516, i=1, __local=3 thread start! tid=23012, i=0, __local=4 > current threads in thread pool is: 2 thread start! tid=23516, i=1, __local=4 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 > current threads in thread pool is: 2 on_thread_exit: thread(23012) exit now > current threads in thread pool is: 1 on_thread_exit: thread(23516) exit now > all worker thread exit now > enter any key to exit