threads5.cpp
593 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
#include <iostream>
#include <thread>
#include "mystring.h"
using namespace std;
::string s (STRING);
void
thread1 (int *p)
{
cout << "Parameter of thread1: " << *p << endl;
*p = 1;
for (unsigned int i = 0; i < COUNT; i++)
{
::string s1 (s);
}
}
void
thread2 (int *p)
{
cout << "Parameter of thread2: " << *p << endl;
*p = 2;
for (unsigned int i = 0; i < COUNT; i++)
{
::string s1 (s);
}
}
int
main ()
{
thread t1;
thread t2;
int r1 = 10, r2 = 11;
t1 = thread (thread1, &r1);
t2 = thread (thread2, &r2);
t1.join();
t2.join();
}