Ò»¸öLinuxÏÂCÏ̳߳صÄʵÏÖ
ʲôʱºòÐèÒª´´½¨Ï̳߳ØÄØ£¿¼òµ¥µÄ˵£¬Èç¹ûÒ»¸öÓ¦ÓÃÐèҪƵ·±µÄ´´½¨ºÍÏú»ÙỊ̈߳¬¶øÈÎÎñÖ´ÐеÄʱ¼äÓַdz£¶Ì£¬ÕâÑùÏ̴߳´½¨ºÍÏú»ÙµÄ´øÀ´µÄ¿ªÏú¾Í²»ÈݺöÊÓ£¬ÕâʱҲÊÇÏ̳߳ظóö³¡µÄ»ú»áÁË¡£Èç¹ûÏ̴߳´½¨ºÍÏú»Ùʱ¼äÏà±ÈÈÎÎñÖ´ÐÐʱ¼ä¿ÉÒÔºöÂÔ²»¼Æ£¬ÔòûÓбØҪʹÓÃÏ̳߳ØÁË¡£ÏÂÃæÊÇLinuxϵͳÏÂÓÃCÓïÑÔ´´½¨µÄÒ»¸öÏ̳߳ء£Ï̳߳ػáά»¤Ò»¸öÈÎÎñÁ´±í(ÿ¸öCThread_worker½á¹¹¾ÍÊÇÒ»¸öÈÎÎñ)¡£pool_init()º¯ÊýÔ¤ÏÈ´´½¨ºÃmax_thread_num¸öỊ̈߳¬Ã¿¸öÏß³ÌÖ´thread_routine ()º¯Êý¡£¸Ãº¯ÊýÖÐ
while (pool->cur_queue_size == 0)
{
pthread_cond_wait (&(pool->queue_ready),&(pool->queue_lock));
}
±íʾÈç¹ûÈÎÎñÁ´±íÖÐûÓÐÈÎÎñ£¬Ôò¸ÃÏ̳߳öÓÚ×èÈûµÈ´ý״̬¡£·ñÔò´Ó¶ÓÁÐÖÐÈ¡³öÈÎÎñ²¢Ö´ÐС£pool_add_worker()º¯ÊýÏòÏ̳߳صÄÈÎÎñÁ´±íÖмÓÈëÒ»¸öÈÎÎñ£¬¼ÓÈëºóͨ¹ýµ÷ÓÃpthread_cond_signal (&(pool->queue_ready))»½ÐÑÒ»¸ö³öÓÚ×èÈû״̬µÄÏß³Ì(Èç¹ûÓеĻ°)¡£pool_destroy ()º¯ÊýÓÃÓÚÏú»ÙÏ̳߳أ¬Ï̳߳ØÈÎÎñÁ´±íÖеÄÈÎÎñ²»»áÔÙ±»Ö´ÐУ¬µ«ÊÇÕýÔÚÔËÐеÄÏ̻߳áÒ»Ö±°ÑÈÎÎñÔËÐÐÍêºóÔÙÍ˳ö¡£ÏÂÃæÌù³öÍêÕû´úÂë
#include
#include
#include
#include
#include
#include
/*
*Ï̳߳ØÀïËùÓÐÔËÐк͵ȴýµÄÈÎÎñ¶¼ÊÇÒ»¸öCThread_worker
*ÓÉÓÚËùÓÐÈÎÎñ¶¼ÔÚÁ´±íÀËùÒÔÊÇÒ»¸öÁ´±í½á¹¹
*/
typedef struct worker
{
/*»Øµ÷º¯Êý£¬ÈÎÎñÔËÐÐʱ»áµ÷Óô˺¯Êý£¬×¢ÒâÒ²¿ÉÉùÃ÷³ÉÆäËüÐÎʽ*/
void *(*process) (void *arg);
void *arg;/*»Øµ÷º¯ÊýµÄ²ÎÊý*/
struct worker *next;
} CThread_worker;
/*Ï̳߳ؽṹ*/
typedef struct
{
pthread_mutex_t queue_lock;
pthread_cond_t queue_ready;
/*Á´±í½á¹¹£¬Ï̳߳ØÖÐËùÓеȴýÈÎÎñ*/
CThread_worker *queue_head;
/*ÊÇ·ñÏú»ÙÏ̳߳Ø*/
int shutdown;
pthread_t *threadid;
/*Ï̳߳ØÖÐÔÊÐíµÄ»î¶¯Ïß³ÌÊýÄ¿*/
int max_thread_num;
/*µ±Ç°µÈ´ý¶ÓÁеÄÈÎÎñÊýÄ¿*/
int cur_queue_size;
} CThread_pool;
int pool_add_worker (void *(*process) (void *arg), void *arg);
void *thread_routine (void *arg);
static CThread_pool *pool = NULL;
void
pool_init (int max_thread_num)
{
pool = (CThread_pool *) malloc (sizeof (CThread_pool));
pthread_mutex_init (&(pool->queue_lock), NULL);
pthread_cond_init (&(pool->queue_ready), NULL);
pool->queue_head = NULL;
pool->max_thread_num = max_thread_num;
pool->cur_queue_siz
Ïà¹ØÎĵµ£º
×ÜÀÀ
ÓÃiptables -ADC À´Ö¸¶¨Á´µÄ¹æ
Ôò
£¬-AÌí¼Ó -Dɾ³ý -C ÐÞ¸Ä
iptables - [RI] chain rule num rule-specification[option]
ÓÃiptables - RI ͨ¹ý¹æÔòµÄ˳ÐòÖ¸¶¨
iptables -D chain rule num[option]
ɾ³ýÖ¸¶¨¹æÔò
iptables -[LFZ] [chain][option]
ÓÃiptables -LFZ Á´Ãû [Ñ¡Ïî]
iptables -[NX] chain
ÓÃ -NX ......
Fork º¯Êý£º
#include <unistd.h>
pid_t fork(void);
ÓÉfork ´´½¨µÄнø³Ì±»³ÆΪ×Ó½ø³Ì¡£fork º¯Êý±»µ÷ÓÃÁ½´Î£¬µ«ÊÇ·µ»ØÁ½´Î¡£Á½´Î·µ»ØµÄΨһÇø±ðÊÇ×Ó½ø³ÌµÄ·µ»ØÖµÊÇ0£¬¶ø¸¸½ø³ÌµÄ·µ»ØÖµÔòÊÇÐÂ×Ó½ø³ÌµÄID¡£½«×Ó½ø³ÌµÄID ·µ»Ø¸ø¸¸½ø³ÌµÄÀíÓÉÊÇ£ºÒ»¸ö½ø³Ì¿ÉÒÔÓжà¸ö×Ó½ø³Ì£¬²¢ÇÒûÓк¯ÊýÊÇÒ»¸ö½ø³Ì»ñµÃÆä×Ó½ø³ÌµÄ½ø³ ......
GCC ÖÐÎÄÊÖ²á
¡¡¡¡http://www.nbfan.com/forum/dispbbs....&ID=1433&page=1
¡¡¡¡GNU make Ö¸ÄÏ
¡¡¡¡http:/ ......