下面是一段双线程运行的模拟程序,请作为作业写出程序的输出结果

#include <stdio.h> 
#include <windows.h>
#include <iostream.h>
#include <winbase.h>

void SubThread(void)
{
int i;
for (i=0;i<5;i++)
{
cout << "SubThread" << i << endl;
Sleep(2000);//改一下时间,输出顺序会有变化
}
}

void main(void)
{
cout << "CreateThread" << endl;

// Create a thread;
DWORD IDThread;
HANDLE hThread;
hThread = CreateThread(NULL, // no security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE) SubThread, // thread function
NULL, // no thread function argument
0, // use default creation flags
&IDThread); // returns thread identifier

// Check the return value for success.
if (hThread == NULL)
cout << "CreateThread error" << endl;

int i;
for (i=0;i<5;i++)
{ cout << "MainThread" << i << endl;
if (i==1)
{ if (SuspendThread(hThread)==0xFFFFFFFF)
{
cout << "Suspend thread error." << endl;
}
else
{
cout << "Suspend thread is ok." << endl;
}
}
if (i==3)
{
if (ResumeThread(hThread)==0xFFFFFFFF)
{
cout << "Resume thread error." << endl;
}
else
{
cout << "Resume thread is ok." << endl;
}
}Sleep(4000);//改一下结果会有变化。
}
}

参考:

MainThread0
SubThread0
SubThread1
MainThread1
SUspend thread is OK
MainThread2
MainThread3
Resume thread is OK
SubThread2
SubThread3
MainThread4
SubThread4