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

来源:互联网 发布:2016年做淘宝赚钱吗 编辑:程序博客网 时间:2024/05/22 00:34

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

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


0 0