pthread_create、pthread_exit、pthread_joinpthread_attr_init、pthread_attr_setdetachstatepthread_mutex_init/lock/unlock/destroypthread_cond_init/wait/signal/broadcast/destroy// 工作節點
typedef struct worker {
void *(*process)(void *arg);
void *arg;
struct worker *next;
} CThread_worker;
// 線程池
typedef struct {
pthread_mutex_t queue_lock;
pthread_cond_t queue_ready;
CThread_worker *queue_head;
int cur_queue_size;
int max_thread_num;
pthread_t *threadid;
int shutdown;
} CThread_pool;
pool_initthread_routine。thread_routinepthread_cond_wait 等待(自動釋放鎖,被喚醒後重新加鎖)。pthread_exit。pool_add_workerpthread_cond_signal 喚醒一個等待線程。pool_destroypthread_cond_broadcast 喚醒所有線程。pthread_join 等待所有線程退出。Java 通過 Executors.newFixedThreadPool/newCachedThreadPool 簡單創建。Tomcat 自定義線程池採用數組存儲空閒線程,按需分批創建(默認 5 個),用完歸還數組。