Windows下pthread多线程使用(5):WaitForAnEnd

声明同这篇文章,以下是代吗

#include <cmnheader.h>

#define THREADGROUPSIZE 5 

void *theThread(void *param)
{
	printf("Thread %.8x %.8x: Entered\n", getpid());
	printf("Thread %.8x %.8x: Working\n", getpid());
	Sleep(15);
	printf("Thread %.8x %.8x: Done with work\n", getpid());
	return NULL;
}
int main(int argc, char **argv)
{
	pthread_t thread[THREADGROUPSIZE];
	void *status[THREADGROUPSIZE];
	int i;
	int rc = 0;
	printf("Enter Testcase - %s\n", argv[0]);
	printf("Create/start some worker threads\n");
	for (i = 0; i < THREADGROUPSIZE; ++i)
	{
		rc = pthread_create(&thread[i], NULL, theThread, NULL);
		checkResults("pthread_create()\n", rc);
	}
	printf("Wait for worker threads to complete, release their resources\n");
	for (i = 0; i < THREADGROUPSIZE; ++i) 
	{
		rc = pthread_join(thread[i], &status[i]);
		checkResults("pthread_join()\n", rc);
	}
	printf("Check all thread's results\n");
	for (i = 0; i < THREADGROUPSIZE; ++i)
	{
		if (status[i] != NULL) 
		{
			printf("Unexpected thread status\n");
		}
	}
	printf("Main completed\n");
	system("pause");
	return 0;
}


转载于:https://www.cnblogs.com/fengyhack/p/10603816.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值