-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpthread_create.c
88 lines (72 loc) · 1.21 KB
/
pthread_create.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* CS360: preempt1.c
* Jim Plank
*/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
int cameraData = 0;
int panoData = 0;
void *cameraloop(void *x)
{
double f;
int i, j, *id;
id = (int *) x;
for (i = 0; i >= 0; i++) {
printf("thread %d. i = %10d\n", *id, i);
f = 1;
#if 0
for (j = 0; j < 90000; j++) {
f = f*.99;
}
#endif
//usleep(500000);
}
return NULL;
}
void *panoloop(void *x)
{
double f;
int i, j, *id;
id = (int *) x;
for (i = 0; i >= 0; i++) {
printf("thread %d. i = %10d\n", *id, i);
f = 1;
#if 0
for (j = 0; j < 90000; j++) {
f = f*.99;
}
#endif
//usleep(500000);
}
return NULL;
}
void *mainloop(void *x)
{
while(1)
{
printf("main mthread---------------***************************-----------------run !\n");
double a = 0.02345673;
#if 1
for(int i =0;i<0xfffffff;i++)
{
a= a*i;
}
#endif
}
return NULL;
}
main()
{
pthread_t t[3];
int i[3];
void *retval;
i[0] = 0;
i[1] = 1;
i[2] = 2;
pthread_create(t, NULL, infloop, i);
pthread_create(t+1, NULL, infloop, i+1);
pthread_create(t+2, NULL, mainloop, i+3);
pthread_join(t[0], &retval);
pthread_join(t[1], &retval);
}