-
Notifications
You must be signed in to change notification settings - Fork 3
/
app4.C
67 lines (52 loc) · 948 Bytes
/
app4.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
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
void DoSleep ()
{
usleep(1);
}
int Calc1 (const int input)
{
int result = input;
for (int i = 0; i < 10000; i++)
{
result += (i*i);
}
DoSleep();
return result;
}
int Calc2 (const int input)
{
int result = input;
for (int i = 0; i < 10000; i++)
{
result += (i*i*i);
}
return result;
}
void* WorkFunc (void* userData)
{
int* value = (int*)userData;
while (1)
{
*value = Calc1(*value);
*value = Calc2(*value);
}
return NULL;
}
int main (int argc, char* argv[])
{
printf("started; PID: %d\n", getpid());
int value1 = 11;
pthread_t threadId;
pthread_create(&threadId, NULL, &WorkFunc, (void*)(&value1));
int value = 10;
while (1)
{
value = Calc1(value);
}
return value;
}