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

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

#include 

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(status) != THREADPASS)
	{
		printf("The thread failed\n");
	}
	printf("Main completed\n");

	system("pause");
	return 0;
}

Windows下pthread多线程使用(3):ExitThread_第1张图片

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

你可能感兴趣的:(Windows下pthread多线程使用(3):ExitThread)