pthread_equal()--Compare Two Threads
Syntax:
#include <pthread.h> int pthread_equal(pthread_t t1, pthread_t t2);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: Yes
The pthread_equal() function compares two Pthread handles for equality.
Authorities and Locks
None.
Parameters
- t1
- (Input) Pthread handle for thread 1
- t2
- (Input) Pthread handle for thread 2
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
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_self()--Get Pthread Handle
- pthread_create()--Create Thread
Example
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#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() 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; }
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
API introduced: V4R3
[ Back to top | Pthread APIs | APIs by category ]