阅读背景:

容易歧义的线程函数SuspendThread、ResumeThread 和如何获知线程是否还在运行_tajon1226的专栏_resumethread函数

来源:互联网 
// Win32Thread.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>


DWORD WINAPI TreadFunc(LPVOID lpParam)
{
	int i = 0;
	while (i < 20)
	{
		printf("I am from a thread, count = %d\n", i++);
	}
	return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE hTread = NULL;
	DWORD dwThreadId = 0;
	hTread = ::CreateThread(NULL, 0, TreadFunc, NULL, 0, &dwThreadId);
	printf("Now another thread has been created. ID=%d\n", dwThreadId);

	::SuspendThread(hTread);
	::SuspendThread(hTread);
	getchar();
	::ResumeThread(hTread);
	getchar();
	::ResumeThread(hTread);

	DWORD dwExitCode;
	if (::GetExitCodeThread(hTread, &dwExitCode))
	{
		if (dwExitCode == STILL_ACTIVE)
		{
			printf("thread still active\n");
		}
		else
		{
			printf("thread exit.\n");
		}
	}

	::WaitForSingleObject(hTread, INFINITE);
	

	if (::GetExitCodeThread(hTread, &dwExitCode))
	{
		if (dwExitCode == STILL_ACTIVE)
		{
			printf("thread still active\n");
		}
		else
		{
			printf("thread exit.\n");
		}
	}

	::CloseHandle(hTread);
	getchar();
	return 0;
}

// Win32Thread.cpp : 定义控制台应用程序的入口点。
//

#includ



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: