Windows下pthread多线程使用(3):ExitThread

本文详细介绍了在Windows操作系统中如何使用pthread库进行多线程编程,重点讨论了ExitThread函数的使用方法及其在多线程上下文中的作用,帮助开发者理解如何优雅地结束线程。
摘要由CSDN通过智能技术生成

声明同上一篇文章,以下是代码

#include <cmnheader.h>

const int THREADFAIL = 1;
const int THREADPASS = 0;

void *theThread(void *parm)
{
	printf("Thread: End with success\n");
	pthread_exit(__VOID(THREADPASS));
	printf("Thread: Did not expect to get here!\n");
	return __VOID(THREADFAIL);
}
int main(int argc, char **argv)
{
	pthread_t thread;
	int rc = 0;
	void *status;
	printf("Enter Testcase - %s\n", argv[0]);
	printf("Create/start a thread\n");
	rc = pthread_create(&thread, NULL, theThread, NULL);
	checkResults("pthread_create()\n", rc);
	printf("Wait for the thread to complete, and release its resources\n");
	rc = pthread_join(thread, &status);
	checkResults("pthread_join()\n", rc);
	printf("Check the thread status\n");
	if (__INT(statu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值