[Prev] [Contents] [Next]

pthread_equal()--Compare Two Threads

Syntax

#include <pthread.h>
int pthread_equal(pthread_t t1, pthread_t t2);
Threadsafe: Yes
Signal Safe: Yes

The pthread_equal() function compares two Pthread handles for equality.

Parameters

t1
(Input) Pthread handle for thread 1
t2
(Input) Pthread handle for thread 2

Authorities and Locks

None.

Return Value

0
The Pthread handles do not refer to the same thread
1
The Pthread handles refer to the same thread

Error Conditions

None.

Related Information

Example

#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include "check.h"

pthread_t   theThread;

void *threadfunc(void *parm)
{
  printf("Inside secondary thread\n");
  theThread = pthread_self();
  return NULL;
}

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() isn't 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;
}

Output

Enter Testcase - QP0WTEST/TPEQU0
Create thread using default attributes
Inside secondary thread
Check if global vs local pthread_t are equal
pthread_equal returns true
Main completed



[Prev] [Contents] [Next]
Copyright © 1998, IBM Corporation. All rights reserved.
Comments? Contact
rchthrds@us.ibm.com