???????????????????????select??????????????????????????????
????????????????????:
1#include"head.h"
2pthread_mutex_tlock;
3pthread_cond_tcond1??cond2;
4void*hand(void*arg)
5{
6pthread_detach(pthread_self());
7TASKtask;
8pQUEUEpq=(pQUEUE)arg;
9while(1)
10{
11get_task(pq??&task);
12excute_task(&task);
13sleep(1);
14}
15}
16intmain(intargc??char*argv[])
17{
18if(argc!=3)
19{
20perror("????????!! ");
21exit(1);
22}
23signal(SIGINT??SIG_IGN);
24signal(SIGPIPE??SIG_IGN);
25signal(SIGQUIT??SIG_IGN);
26QUEUEque;
27intfd;
28fd_setread_set??revc;
29pFDlist;
30memset(&que??0??sizeof(QUEUE));
31fd_init(&list);
32intcnt=atoi(argv[2]);
33pthread_t*arr=(pthread_t*)calloc(cnt??sizeof(pthread_t));
34pthread_mutex_init(&lock??NULL);
35pthread_cond_init(&cond1??NULL);
36pthread_cond_init(&cond2??NULL);
37intindex=0;
38while(cnt>0)
39{
40pthread_create(arr+index??NULL??hand??(void*)&que);
41cnt--;
42index++;
43}
44fd=open(argv[1]??O_RDONLY);
45if(fd==-1)
46{
47perror("????????!! ");
48exit(1);
49}
50structtimevaltm;
51intret;
52FD_ZERO(&read_set);
53FD_ZERO(&revc);
54FD_SET(fd??&read_set);
55while(1)
56{
57tm.tv_sec=0;
58tm.tv_usec=1000;
59revc=read_set;
60ret=select(1024??&revc??NULL??NULL??&tm);
61if(ret==0)
62continue;
63elseif(ret>0)
64{
65if(FD_ISSET(fd??&revc))
66{
67charbuf[32];
68memset(buf??0??32);
69if(read(fd??buf??32)==0)
70continue;
71else
72{
73charname[32];
74intr_fd??w_fd;
75buf[strlen(buf)-1]='