|
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
volatile static int index=0;
DWORD WINAPI Fun1Proc(LPVOID lpParameter);
int main(int argc, char* argv[])
{
The
HANDLE hThread1;
hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
CloseHandle(hThread1);
WaitForSingleObject(hThread1,INFINITE);
while(index++<1000)
{
cout<<"Main thread is runing"<<endl;
}
return 0;
}
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
while(index++<1000)
{
cout<<"Thread1 is running"<<endl;
}
return 0;
}
It is still wrong to change to the above.
But I can’t lose anything by changing to the following
// MultThread.cpp: Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
volatile static int index=0;
DWORD WINAPI Fun1Proc(LPVOID lpParameter);
int main(int argc, char* argv[])
{
The
HANDLE hThread1;
hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
CloseHandle(hThread1);
WaitForSingleObject(hThread1,INFINITE);
/* while(index++<1000)
{
cout<<"Main thread is runing"<<endl;
}
*/
return 0;
}
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
while(index++<1000)
{
cout<<"Thread1 is running"<<endl;
}
return 0;
}
Multi-threaded |
|