threads5.cpp
812 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
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include "mystring.h"
string s ("ala");
void *
thread1 (void *p)
{
int *pp = (int *) p;
printf ("Parameter of thread1: %d\n", *pp);
*pp = 1;
for (unsigned int i = 0; i < 100000; i++)
{
string s1 (s);
}
pthread_exit (p);
}
void *
thread2 (void *p)
{
int *pp = (int *) p;
printf ("Parameter of thread2: %d\n", *pp);
*pp = 2;
for (unsigned int i = 0; i < 100000; i++)
{
string s1 (s);
}
pthread_exit (p);
}
int
main ()
{
pthread_t t1;
pthread_t t2;
int *retval1;
int *retval2;
int r1 = 10, r2 = 11;
pthread_create (&t1, NULL, thread1, &r1);
pthread_create (&t2, NULL, thread2, &r2);
pthread_join (t1, (void **) &retval1);
pthread_join (t2, (void **) &retval2);
printf ("%d\n", *retval1);
printf ("%d\n", *retval2);
}