码迷,mamicode.com
首页 > 其他好文 > 详细

EXITTHRD.C--示范ExitThread()

时间:2015-07-22 16:21:43      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:


#define WIN32_LEAN_AND_MEAN
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>


DWORD WINAPI ThreadFunc(LPVOID);
void AnotherFunc(void);


int main()
{
HANDLE hThrd;
DWORD exitCode = 0;
DWORD threadId;
hThrd = CreateThread(NULL, 0, ThreadFunc, (LPVOID)1, 0, &threadId);
if (hThrd)
printf("Thread launched\n");
for (;;)
{
BOOL rc;
rc = GetExitCodeThread(hThrd, &exitCode);
if (rc && exitCode != STILL_ACTIVE)
break;
}
CloseHandle(hThrd);


printf("Thread returned %d \n", exitCode);
return EXIT_SUCCESS;
}
/*Call a function to do something that terminates the thread
with ExitThread instead of returning*/
DWORD WINAPI ThreadFunc(LPVOID n)
{
printf("Thread running\n");
AnotherFunc();
return 0;
}
void AnotherFunc()
{
printf("About to exit thread\n");
ExitThread(4);
//it is impossible to get here, this line will never be printed
printf("This will never print\n");
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

EXITTHRD.C--示范ExitThread()

标签:

原文地址:http://blog.csdn.net/wangfengfan1/article/details/47002117

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!