threadsafe7.c
549 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
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
volatile int c;
void *
thread (void *param)
{
int i;
for (i = 0; i < 10000; i++)
{
c=c*123413123+7;;
}
pthread_exit (param);
}
int
main (int argc, char *argv[])
{
pthread_t t1, t2;
pthread_attr_t attr;
int a, b;
void *retval;
a = 0;
pthread_attr_init (&attr);
pthread_create (&t1, &attr, thread, &a);
if (argc > 1)
{
b = 10000;
pthread_create (&t2, &attr, thread, &b);
pthread_join (t2, &retval);
};
pthread_join (t1, &retval);
printf("c=%d\n",c);
exit (0);
}