int main(int argc, char *argv[]) { thread_pool_handle *handle; int i; handle = thread_pool_init(10); if(!handle){ printf("thread_pool_init error!\n"); return -1; } sleep(3); for(i=0;i<10;i++){ thread_pool_add_worker(handle, try_printf, &i); sleep(1); } sleep(10); thread_pool_exit(handle); }
void thread_pool_destroy(thread_pool_t *this_ptr) { int i; if (this_ptr != NULL) { if (this_ptr->continue_thread_pool) { thread_pool_exit(this_ptr); for(i = 0; i < this_ptr->thread_size; i++) { pthread_join(this_ptr->threads[i], NULL); pthread_detach(this_ptr->threads[i]); } } pthread_mutex_destroy(this_ptr->mutex); pthread_cond_destroy(this_ptr->condititon); free(this_ptr->mutex); free(this_ptr->condititon); queue_destroy(this_ptr->queue); free(this_ptr->threads); free(this_ptr); } }