-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDemo.cpp
53 lines (49 loc) · 1.73 KB
/
Demo.cpp
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
#include "stdafx.h"
#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#include <concrt.h>
#include <ppl.h>
class employee
{
char name_[128];
unsigned id_;
public:
employee(char const* name, unsigned id) : id_(id)
{
strcpy_s(name_, name);
}
};
void process_employees()
{
try {
auto emp = new employee("David", 123);
auto emp1 = new employee("David2", 123);
delete emp1;
auto p = HeapAlloc(GetProcessHeap(), 0, 100);
p = HeapReAlloc(GetProcessHeap(), 0, p, 200);
}
catch (...) {
printf("Employee creation failed.\n");
}
}
DWORD WINAPI Thread(LPVOID)
{
while (true)
{
Sleep(1000);
process_employees();
}
return 0;
}
int main()
{
for (int i = 0; i < 4; ++i)
{
CreateThread(nullptr, 0, Thread, nullptr, 0, nullptr);
}
Sleep(INFINITE);
return 0;
}