⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tpool.h

📁 linux下多线程程序设计,包括signals,mutex,simple_once
💻 H
字号:
/********************************************************
 * An example source module to accompany...
 *
 * "Using POSIX Threads: Programming with Pthreads"
 *     by Brad nichols, Dick Buttlar, Jackie Farrell
 *     O'Reilly & Associates, Inc.
 *
 ********************************************************
 * tpool.h --
 *
 * Structures for thread pool
 */

typedef struct tpool_work {
	void               (*routine)(void *);
	void                *arg;
	struct tpool_work   *next;
} tpool_work_t;

typedef struct tpool 
{
	/* pool characteristics */
	int                 num_threads;
	int                 max_queue_size;
	int                 do_not_block_when_full;
	/* pool state */
	pthread_t           *threads;
	int                 cur_queue_size;
	tpool_work_t        *queue_head;
	tpool_work_t        *queue_tail;
	int                 queue_closed;
	int                 shutdown;
	/* pool synchronization */
	pthread_mutex_t     queue_lock;
	pthread_cond_t      queue_not_empty;
	pthread_cond_t      queue_not_full;
	pthread_cond_t      queue_empty;
} *tpool_t;

void tpool_init(tpool_t *tpoolp, int num_threads, int max_queue_size, int do_not_block_when_full);

int tpool_add_work(tpool_t tpool, void (*routine)(void *), void *arg);

int tpool_destroy(tpool_t tpool, int finish);


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -