elem_t que_top(pque_t pq) { pthread_mutex_lock(&pq ->que_lock); while(EMPTY == que_empty(pq)) { pthread_cond_wait(&pq ->que_con, &pq ->que_lock); } return pq ->que_arr[pq ->que_front] ; }
/*while(1):<获取线程池/获取报文队列/判断队列是否为空(若空则条件等待)/若非空,则让队列头元素出队/执行服务端的服务> */ void* thread_handle(void* arg) { while(1) { pool* p=(pool*)arg; printf("the start is %d\n",p->start); que* q=&p->q; node n; if(que_empty(q)) { pthread_cond_wait(&p->cond,&q->mutex); pthread_mutex_unlock(&q->mutex); } que_pop(q,&n); server_do(&n); } }