首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

Linux多线程学习(5)pthread_equal

2012-09-20 
Linux多线程学习(五)pthread_equal#define _MULTI_THREADED#include pthread.h#include stdio.hpthrea

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

热点排行