Linux多线程学习(5)pthread_equal

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;}

Linux多线程学习(5)pthread_equal

相关文章:

你感兴趣的文章:

标签云: