Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎĵµ£º

ÔÚLinuxϱàÒëʹÓÃkfs

±àÒë°²×°KFS£º
kfs:kosmosfs
環¾³:
os:centos5.3
metaserver£ºVM-CentOS-5-SHU
chunkservers:VM-CentOS-5-SHU-2,VM-CentOS-5-SHU-3,VM-CentOS-5-SHU-4
ǰÌáÌõ¼þ£ºssh¤Ç¥Ñ¥¹¥ïー¥É無¤·¤Ç認証¤Ë¤Ê¤ë
kfs¤Î¥¤¥ó¥¹¥Èー¥ë
metaserver¤ÇÏÂ記¤Î²Ù×÷¤òÐФ¦
Ò»¡¢±ØÒª¥Ñ¥Ã¥±} ......

LINUX Ï̺߳¯Êý´óÈ«

LINUX Ï̺߳¯Êý´óÈ«
±¾ÎÄÀ´×ÔCSDN²©¿Í£¬³ö´¦£ºhttp://blog.csdn.net/ShowMan/archive/2009/09/22/4580295.aspx
Ïß³Ì
´´½¨Ò»¸öȱʡµÄÏß³Ì
ȱʡµÄÏ̵߳ÄÊôÐÔ£º
l         ·Ç°ó¶¨
l         δ·ÖÀë
l     & ......

³£ÓõÄlinuxÃüÁî

²é¿´°²×°µÄϵͳÐÅÏ¢£º
   ¼òµ¥µÄÐÅÏ¢£ºuname -a
   ÏêϸµÄÐÅÏ¢£ºcat /proc/version
     cat /etc/issue
     lsb_release -a
GentooÉϰ²×°mysql£¬Ö±½ÓÔËÐУº
  (1) bigner
@localhost
 / $ sudo emerge mysql
  ......

Linux curlʹÓüòµ¥½éÉÜ

CurlÊÇLinuxÏÂÒ»¸öºÜÇ¿´óµÄhttpÃüÁîÐй¤¾ß£¬Æä¹¦ÄÜÊ®·ÖÇ¿´ó¡£
1£©¶ÁÈ¡ÍøÒ³
$ curl linuxidc.com">http://www.linuxidc.com
2£©±£´æÍøÒ³
$ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com
3£©Ê¹ÓõÄproxy· ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ