Advertisement
STANAANDREY

thread joinability

Nov 28th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <pthread.h>
  2.  
  3. int check_thread_joinable(pthread_t thread) {
  4.     pthread_attr_t attr;
  5.     int detachstate;
  6.     int result;
  7.  
  8.     // Get thread attributes
  9.     result = pthread_getattr_np(thread, &attr);
  10.     if (result != 0) {
  11.         return -1; // Error getting attributes
  12.     }
  13.  
  14.     // Get detach state
  15.     result = pthread_attr_getdetachstate(&attr, &detachstate);
  16.     if (result != 0) {
  17.         pthread_attr_destroy(&attr);
  18.         return -1; // Error getting detach state
  19.     }
  20.  
  21.     // Clean up
  22.     pthread_attr_destroy(&attr);
  23.  
  24.     // Return whether thread is joinable
  25.     return (detachstate == PTHREAD_CREATE_JOINABLE);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement