请用C++写一个线程池
时间: 2023-05-18 13:04:55 浏览: 79
《Linux下分别使用C和C++语言实现线程池》里的线程池图;仅供自己使用;请不要下载。
我可以为您编写一个C语言实现的线程池示例: #include<pthread.h>
#define MAX_THREAD 5
/* data structure to pass to the thread functions */
typedef struct thread_data_s {
int id;
} thread_data_t;
/* thread pool context */
typedef struct thread_pool_s {
pthread_t threads[MAX_THREAD];
thread_data_t thread_data[MAX_THREAD];
int thread_count;
} thread_pool_t;
/* thread pool functions */
int thread_pool_init(thread_pool_t *pool);
int thread_pool_add_thread(thread_pool_t *pool, void*(*start_routine)(void*), void *arg);
int thread_pool_wait(thread_pool_t *pool);
void thread_pool_destroy(thread_pool_t *pool);
阅读全文