Linux下调用pthread库实现简单线程池
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include <assert.h>
void * routine(void * arg);
int pool_add_job(void *(*process)(void * arg),void *arg);
int pool_init(unsigned int thread_num);
int pool_destroy(void);
void *test(void *);
/* We define a queue of jobs which will be processed in thread pool*/
typedef struct job{
void * (*process)(void *arg); /* process() will employed on job*/
void *arg;/* argument to process */
struct job * next;
}Job;
/*
* A threadpool must have the following parts:
* threads: a list of threads
* jobs : jobs in thread pool
* pool_lock: pthread_mutex_lock for thread pool
* job_ready: pthread_cond_t for job ready
* destroy: flag indicate whether the pool shall be destroyed
* size: current size of jobs list
* thread_num: max thread num initialized in pool
*/
typedef struct thread_pool{
pthread_mutex_t pool_lock;
pthread_cond_t job_ready;
Job * jobs;
int destroy;
pthread_t * threads;
unsigned int thread_num;
int size;
}Thread_pool;
/* global Thread_pool variable*/
static Thread_pool * pool=NULL;
/*Initialize the thread pool*/
int pool_init(unsigned int thread_num)
{
pool=(Thread_pool *)malloc(sizeof(Thread_pool));
if(NULL==pool)
return -1;
pthread_mutex_init(&(pool->pool_lock),NULL);
pthread_cond_init(&(pool->job_ready),NULL);
pool->jobs=NULL;
pool->thread_num=thread_num;
pool->size=0;
pool->destroy=0;
pool->threads=(pthread_t *)malloc(thread_num * sizeof(pthread_t));
int i;
for(i=0;i<thread_num;i++){
pthread_create(&(pool->threads[i]),NULL,routine,NULL);
}
return 0;
}
/*
* Add job into the pool
* assign it to some thread
*/
int pool_add_job(void *(*process)(void *),void *arg)
{
Job * newjob=(Job *)malloc(sizeof(Job));
newjob->process=process;
newjob->arg=arg;
newjob->next=NUL
相关文档:
安装mysql
sudo apt-get install mysql-servel-5.0 mysql-client-5.0
下载安装过程中,会提示输入root密码
安装C语言编程接口:
sudo apt-get install libmysqlclient15-dev
更多api 查看:http://dev.mysql.com/doc/refman/5.0/en/c.html
相关mysql头文件和库文件安装在/usr/include/mysql/和/usr/lib/mysql目 ......
准备工作:
用到的perl 扩展组件(modules)在上篇贴出.( win32::odbc 模块
)下载组件后按照Readme文件安装倒响应目录.配置好相应的odbc数据源.
程序实现:
使用
use
Win32::ODBC;
语句包含应使用的模块是win32::odbc,写出数据库
连接字符串
$DSN = "DSN =
My DSN ......
查看安装的系统信息:
简单的信息:uname -a
详细的信息:cat /proc/version
cat /etc/issue
lsb_release -a
Gentoo上安装mysql,直接运行:
(1) bigner
@localhost
/ $ sudo emerge mysql
  ......
ORACLE ebs 11.5.10.2 for linux as4 安装心得
metalink:
316806.1
参考博友:自由的风
目录
前言
第一章 硬件准备
第二章 软件准备
第三章 11.5.10 For Linux 安装
第四章 安装后的维护和问题解决
第五章 ebs对外的发布
ORACLE EBS 11.5.10 学习笔记(安装篇)
前 言
第一章 硬件准备
我公司安装机 ......