Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

Mysql for linux mysql×Ô¶¯±¸·Ý½Å±¾

¿ÉÒÔ½«Õâ¸ö½Å±¾·Å½øcrontab£¬ËûµÄÅäÖÆÎļþÔÚ /etc/crontabÖÐÿÌìÁ賿ִÐÐÒ»´Î£¬×Ô¶¯±¸·Ý Õâ¸ö½Å±¾Ã¿Ìì×î¶àÖ»Ö´ÐÐÒ»´Î£¬¶øÇÒÖ»±£Áô×î½üÎåÌìµÄ±¸·ÝÔÚ·þÎñÆ÷ÉÏ¡£
#!/bin/bash
#This is a ShellScript For Auto DB Backup
#Powered by aspbiz
#2004-09
#Setting
#ÉèÖÃÊý¾Ý¿âÃû£¬Êý¾Ý¿âµÇ¼Ãû£¬ÃÜÂ룬±¸·Ý·¾¶£¬ÈÕ־ ......

ÔÚlinuxÏ°²×°ºÍÅäÖÃApache+PHP

£¨1£© °²×°ºÍÅäÖÃApache
      ÔÚÈçÏÂÒ³ÃæÏÂÔØapacheµÄfor Linux µÄÔ´Âë°ühttp://www.apache.org/dist/httpd/
¡¡¡¡´æÖÁ/home/xxĿ¼£¬xxÊÇ×Ô½¨Îļþ¼Ð£¬ÎÒ½¨ÁËÒ»¸öwhyµÄÎļþ¼Ð¡£
¡¡¡¡ÃüÁîÁÐ±í£º¡¡¡¡
              & ......

rename¡¡linux º¯Êý

C±ê×¼º¯Êý£¬Ëƺõ²»Ó¦¸ÃÓÐƽ̨ÎÊÌ⣺ ÎÒÃÇ¿´Ò»ÏÂÕâ¸ö³ÌÐò£º #include
#include
int main()
{
    rename(¡±/tmp/abc¡±,¡±/tmp/bcd¡±);
    perror(¡±why:¡±);
} ´Ë³ÌÐòÔËÐÐÒ»ÇÐÕý³£¡£ ×Ô¼º½«Â·¾¶ÐÞ¸ÄΪ²»Í¬µÄ·ÖÇøÖ®¼äÒƶ¯£¬»òÕß½«Í¬Ò»·ÖÇø¹ÒÔص½²»Í¬µÄmou ......

LINUX Ï̺߳¯Êý´óÈ«

LINUX Ï̺߳¯Êý´óÈ«
±¾ÎÄÀ´×ÔCSDN²©¿Í£¬³ö´¦£ºhttp://blog.csdn.net/ShowMan/archive/2009/09/22/4580295.aspx
Ïß³Ì
´´½¨Ò»¸öȱʡµÄÏß³Ì
ȱʡµÄÏ̵߳ÄÊôÐÔ£º
l         ·Ç°ó¶¨
l         δ·ÖÀë
l     & ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ