pthread_equal() — Compare thread IDs

Standards

Standards / Extensions C or C++ Dependencies

POSIX.4a
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _OPEN_THREADS
#include <pthread.h>

int pthread_equal(pthread_t t1, pthread_t t2);

General description

Compares the thread IDs of t1 and t2.

pthread_t is the data type used to uniquely identify a thread. It is returned by pthread_create() and used by the application in function calls that require a thread identifier.

Returned value

If t1 and t2 are equal, pthread_equal() returns a positive value. Otherwise, the value 0 is returned. If t1 or t2 are not valid thread IDs, the behavior is undefined.

If unsuccessful, pthread_equal() returns -1.

There are no documented errno values. Use perror() or strerror() to determine the cause of the error.

Example

CELEBP29
⁄* CELEBP29 *⁄                                   
#define _OPEN_THREADS                                                           
#include <pthread.h>                                                            
#include <stdio.h>                                                              
                                                                                
pthread_t thid, IPT;                                                            
                                                                                
void *thread(void *arg) {                                                       
  if (pthread_equal(IPT, thid))                                                 
    puts("the thread is the IPT...?");                                          
  else                                                                          
    puts("the thread is not the IPT");                                          
}                                                                               
                                                                                
main() {                                                                        
                                                                                
  IPT = pthread_self();                                                         
                                                                                
  if (pthread_create(&thid, NULL, thread, NULL) != 0) {                         
    perror("pthread_create() error");                                           
    exit(1);                                                                    
  }                                                                             
                                                                                
  if (pthread_join(thid, NULL) != 0) {                                          
    perror("pthread_create() error");                                           
    exit(3);                                                                    
  }                                                                             
}                                                                               
Output:
the thread is not the IPT

Related information