15,471
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <iostream>
using namespace std;
DWORD WINAPI MyThread1(
LPVOID lpParameter
);
DWORD WINAPI MyThread2(
LPVOID lpParameter
);
int Index=0;
int tickets=30;
int main()
{
HANDLE handle1;
HANDLE handle2;
handle1=CreateThread(NULL,0,MyThread1,NULL,0,NULL);
handle2=CreateThread(NULL,0,MyThread2,NULL,0,NULL);
CloseHandle(handle1);
CloseHandle(handle2);
Sleep(1000);
return 0;
}
DWORD WINAPI MyThread1(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets>0)
cout<<"The tickets is: "<<tickets--<<endl;
else
break;
}
return 0;
}
DWORD WINAPI MyThread2(LPVOID lpParameter)
{
while(TRUE)
{
if(tickets>0)
cout<<"The tickets is: "<<tickets--<<endl;
else
break;
}
return 0;
}
输出怎么是这个样啊?好乱啊!!!
ThTeh tickets is: e tickets is: 320
The tickets is:9
The tickets is: 27
The tickets is 2: 26
The tickets i8
The tickets is: 24
The tickets iss:: 23
The tickets 25
The tickets iis: 22
The ticketss: 21
The tickets is: 19
The ticket iss: 20
The ticket is: 18
The tickets is: 16
The ticksets is: 15
The tic is: 17
The tickets is: 13
The tickkeets is: 14
The tits is: 12
The tickets is: 10
The ticckets is: 11
The tkets is: 9
The tickets is: 7
The tiicckets is: 8
The tkets is: 6
The tickets is: 4
The tiicckets is: 5
The tkets is: 3
The tickets is: 1
ickets is: 2
Press any key to continue