|
楼主 |
发表于 2020-6-30 10:45:01
|
显示全部楼层
#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[])
{
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;
}
改成上面这个样子还是出错。
但是改成下面的样子却什么都输不出
// 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[])
{
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;
}
多线程好晕 |
|