孙鑫vc++里面多线程的代码在6.0里面编译和生成都没有提示错误,执行时提示错误,文件夹下没有生成exe文件
建立的是win32控制台程序#include<windows.h>#include<iostream.h>DWORDWINAPIFun1RROC(LPVOIDlpPara...
建立的是win32控制台程序
#include <windows.h>
#include <iostream.h>
DWORD WINAPI Fun1RROC(LPVOID lpParameter);
DWORD WINAPI Fun2RROC(LPVOID lpParameter);
int index = 0;
int tickets = 100;
void main()
{
HANDLE hThread1;
HANDLE hThread2;
// hThread1 = _beginthreadex(NULL,0,Fun1PROC,NULL,0,NULL);
// hThread1 = _beginthreadex(NULL,0,Fun2PROC,NULL,0,NULL);
hThread1 = CreateThread(NULL,0,Fun1PROC,NULL,0,NULL);
hThread2 = CreateThread(NULL,0,Fun2PROC,NULL,0,NULL);
CloseHandle(hThread1);
CloseHandle(hThread2);
Sleep(4000);
}
DWORD WINAPI Fun1PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread1 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
DWORD WINAPI Fun2PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread2 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
} 展开
#include <windows.h>
#include <iostream.h>
DWORD WINAPI Fun1RROC(LPVOID lpParameter);
DWORD WINAPI Fun2RROC(LPVOID lpParameter);
int index = 0;
int tickets = 100;
void main()
{
HANDLE hThread1;
HANDLE hThread2;
// hThread1 = _beginthreadex(NULL,0,Fun1PROC,NULL,0,NULL);
// hThread1 = _beginthreadex(NULL,0,Fun2PROC,NULL,0,NULL);
hThread1 = CreateThread(NULL,0,Fun1PROC,NULL,0,NULL);
hThread2 = CreateThread(NULL,0,Fun2PROC,NULL,0,NULL);
CloseHandle(hThread1);
CloseHandle(hThread2);
Sleep(4000);
}
DWORD WINAPI Fun1PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread1 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
DWORD WINAPI Fun2PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread2 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
} 展开
1个回答
展开全部
#include <windows.h>
#include <iostream>
using namespace std;
int index = 0;
int tickets = 100;
DWORD WINAPI Fun1PROC( LPVOID lpParam );
DWORD WINAPI Fun2RROC(LPVOID lpParameter);
int main()
{
HANDLE hThread1;
HANDLE hThread2;
hThread1 =::CreateThread(NULL,0,Fun1PROC,NULL,0,NULL);
hThread2 =::CreateThread(NULL,0,Fun2RROC,NULL,0,NULL);
CloseHandle(hThread1);
Sleep(4000);
return 0;
}
DWORD WINAPI Fun1PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread1 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
DWORD WINAPI Fun2RROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread2 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
没问题,可能是你直接复制粘贴了一些不可见字符??你手动敲一遍两个Proc声明定义
#include <iostream>
using namespace std;
int index = 0;
int tickets = 100;
DWORD WINAPI Fun1PROC( LPVOID lpParam );
DWORD WINAPI Fun2RROC(LPVOID lpParameter);
int main()
{
HANDLE hThread1;
HANDLE hThread2;
hThread1 =::CreateThread(NULL,0,Fun1PROC,NULL,0,NULL);
hThread2 =::CreateThread(NULL,0,Fun2RROC,NULL,0,NULL);
CloseHandle(hThread1);
Sleep(4000);
return 0;
}
DWORD WINAPI Fun1PROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread1 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
DWORD WINAPI Fun2RROC(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets<0)
cout<<"thread2 sell ticket : "<<tickets--<<endl;
else
break;
}
return 0;
}
没问题,可能是你直接复制粘贴了一些不可见字符??你手动敲一遍两个Proc声明定义
追问
谢谢这位朋友,我手动输入了还是不行的哦,有没有可能工程属性需要设置什么啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询