一个线程池的简单模型
时间:2010-05-26 来源:chinaltang
1 #include<pthread.h>
2 #include<semaphore.h>
3 typedef struct work{
4 void* (*thread)(void*);
5 void * arg;
6 struct work *next;
7 }threadpool_work;
8
9 typedef struct threadpool{
10 threadpool_work* head;
11 pthread_t* pid;
12 int current_size;
13 int max_thread_size;
14 pthread_mutex_t list_lock;
15 pthread_cond_t work_avilable;
16 int shutdown;
17 }*threadpool_t;
18
19 void threadpool_init(threadpool_t* tpool,int max_thread_size);
20 void threadpool_add_work(threadpool_t* tpool,void* (*pthread)(void *),void* arg);
21 void* threadpool_get_work(threadpool_t* tpool);
22 void threadpool_destroy(threadpool_t* tpool);
2 #include<semaphore.h>
3 typedef struct work{
4 void* (*thread)(void*);
5 void * arg;
6 struct work *next;
7 }threadpool_work;
8
9 typedef struct threadpool{
10 threadpool_work* head;
11 pthread_t* pid;
12 int current_size;
13 int max_thread_size;
14 pthread_mutex_t list_lock;
15 pthread_cond_t work_avilable;
16 int shutdown;
17 }*threadpool_t;
18
19 void threadpool_init(threadpool_t* tpool,int max_thread_size);
20 void threadpool_add_work(threadpool_t* tpool,void* (*pthread)(void *),void* arg);
21 void* threadpool_get_work(threadpool_t* tpool);
22 void threadpool_destroy(threadpool_t* tpool);
相关阅读 更多 +
排行榜 更多 +