读书人

Linux多线程学习(5)pthread_equal

发布时间: 2012-09-20 09:36:50 作者: rapoo

Linux多线程学习(五)pthread_equal

#define _MULTI_THREADED#include <pthread.h>#include <stdio.h>pthread_t   theThread;
static void checkResults(char *string, int rc) {  if (rc) {    printf("Error on : %s, rc=%d",           string, rc);    exit(EXIT_FAILURE);  }  return;}
void *threadfunc(void *parm){  printf("Inside secondary thread\n");  theThread = pthread_self();  return NULL;}
static void checkResults(char *string, int rc) {  if (rc) {    printf("Error on : %s, rc=%d",           string, rc);    exit(EXIT_FAILURE);  }  return;}
int main(int argc, char **argv){ pthread_t thread; int rc=0; printf("Enter Testcase - %s\n", argv[0]); printf("Create thread using default attributes\n"); rc = pthread_create(&thread, NULL, threadfunc, NULL); checkResults("pthread_create()\n", rc); /* sleep() is not a very robust way to wait for the thread */ sleep(5); printf("Check if global vs local pthread_t are equal\n"); if (!pthread_equal(thread, theThread)) { printf("Unexpected results on pthread_equal()!\n"); exit(1); } printf("pthread_equal returns true\n"); printf("Main completed\n"); return 0;}

读书人网 >UNIXLINUX

热点推荐