- 论坛徽章:
- 0
|
01 #include <stdio.h>
02 #include <time.h>
03 #include <sys/time.h>
04 #include <stdlib.h>
05 #include <signal.h>
06
07 int count = 0;
08
09 void thread1(void) {
10
11 while (1)
12 printf("1");
13
14 }
15
16 void thread2(void) {
17
18 while(1)
19 printf("2");
20
21 }
22
23
24 void set_timer() {
25
26 struct itimerval itv, oldtv;
27
28 itv.it_interval.tv_sec = 5;
29 itv.it_interval.tv_usec = 0;
30 itv.it_value.tv_sec = 5;
31 itv.it_value.tv_usec = 0;
32
33 setitimer(ITIMER_REAL, &itv, &oldtv);
34
35 }
36
37 void sigalrm_handler(int sig) {
38
39 int i;
40 count++;
41
42 for(i = 0; i < 100; i++)
43 printf("3");
44
45 }
46
47 int main() {
48
49 pthread_t id1, id2;
50
51 signal(SIGALRM, sigalrm_handler);
52 set_timer();
53
54
55 pthread_create(&id1, NULL, (void*) thread1, NULL);
56 pthread_create(&id2, NULL, (void*) thread2, NULL);
57
58 while(1)
59 ;
60
61 pthread_join(id1, NULL);
62 pthread_join(id2, NULL);
63
64 return 0;
65
66 }
可以解释一下你的程序里第58 - 59行是干什么的吗? |
|