- 论坛徽章:
- 0
|
1 #include<pthread.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include <unistd.h>
5 #include <time.h>
6
7 static int flag = 1;
8 pthread_mutex_t mutex_t = PTHREAD_MUTEX_INITIALIZER;
9 void *create_p(void *arg){
10 int status = pthread_mutex_lock(&mutex_t);
11 printf("this pthread is number %d\n",flag);
12 flag++;
13 if(status !=0){
14 exit(1);
15 }
16 pthread_mutex_unlock(&mutex_t);
17 }
18
19 int main(){
20 pthread_t tid[19];
21 int i = 0;
22 int status;
23 for(i = 0; i<30;i++){
24 printf("%d\n",i);
25 status = pthread_create(&tid,NULL,create_p,NULL);
26 if(status != 0){
27 printf("create_thread error\n");
28 exit(1);
29 }
30 }
31 return 0;
32
33 }
为什么在tid[20]的时候,还向下运行了一个循环的?
~ |
|