-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpools.c
More file actions
41 lines (32 loc) · 716 Bytes
/
Copy pathpools.c
File metadata and controls
41 lines (32 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <pthread.h>
void *thread_func(void *data)
{
int *i = data;
while (1) {
printf("----------------------------\n");
sleep(1);
printf("tid-> [%lu] i %d\n", pthread_self(), *i);
(*i) ++;
printf("----------------------------\n");
}
}
int main()
{
int array[8];
int i;
pthread_t tid[8];
int ret;
for (i = 0; i < 8; i ++) {
array[i] = 0;
ret = pthread_create(&tid[i], NULL, thread_func, &array[i]);
if (ret < 0) {
printf("failed to create thread\n");
return -1;
}
}
for (i = 0; i < 8; i ++) {
pthread_join(tid[i], NULL);
}
return 0;
}