Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "windows.h" //Included to Use Windows Functions
- #include <iostream>
- #include <cstdio>
- using namespace std;
- DWORD WINAPI ThreadFn (LPVOID vpParam); //Prototype of Function that will contain the code for the new thread
- int main()
- {
- unsigned int count=0;
- DWORD ThreadId; //Variable to Hold ThreadID
- HANDLE hThread=CreateThread(0,0,ThreadFn,&count,0,&ThreadId); //SystemCall to Create Thread
- //Loop Until User Presses q
- char ch=' ';
- while(ch!='q')
- {
- cout<<endl<<count;
- ch=(char)getchar();
- }
- return 0;
- }
- //Thread Function Definition
- DWORD WINAPI ThreadFn (LPVOID vpParam)
- {
- unsigned int &counter=*((unsigned int*)vpParam); //Dereferencing the void pointer after casting to unsigned int and assigning it to a local reference
- cout<<"\nInside New Thread!";
- while(counter<0xFFFFFFFF)
- counter++;
- return 0; //End of Thread
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement