-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMultiThreading.cpp
More file actions
45 lines (34 loc) · 1.06 KB
/
CMultiThreading.cpp
File metadata and controls
45 lines (34 loc) · 1.06 KB
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
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
DWORD Sum; /* data is shared by the thread */
DWORD WINAPI Summation(LPVOID Param)
{
DWORD Upper = *(DWORD*)Param;
for (DWORD i = 0; i <= Upper; i++)
Sum += i;
for (DWORD i = 0; i <= 99999; i++)
char* temp = (char*) malloc(sizeof(char));
return 0;
}
void multiThreadingTest()
{
DWORD Threadid;
HANDLE ThreadHandle;
int Param = 5 ;
ThreadHandle = CreateThread(
NULL, // default security attributes
0, // default stack size
Summation, // thread function
&Param, // parameter to thread function
0, // default creation flags
&Threadid); // returns the thread identifier '
if(ThreadHandle != NULL)
{
// now wait for the thread to finish
WaitForSingleObject(ThreadHandle,INFINITE);
// close the thread handle
CloseHandle(ThreadHandle);
printf("surn = %d\n" ,Sum);
}
}