pthread_attr_getguardsize() - Get guardsize attribute

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 3

both

z/OS V1R9
POSIX(ON)

Format

#define _UNIX03_THREADS
#include <pthread.h>

int pthread_attr_getguardsize(const pthread_attr_t *__restrict__ attr,
                              size_t ** __restrict__ guardsize); 

General description

pthread_attr_getguardsize() gets the guardsize attribute from attr and stores it into guardsize.

attr is a pointer to a thread attribute object initialized by pthread_attr_init().

The retrieved guardsize always matches the size stored by pthread_attr_setguardsize(), despite internal adjustments for rounding to multiples of the PAGESIZE system variable.

Returned value

If successful, pthread_attr_getguardsize() returns 0; otherwise it returns an error number.

Error Number
Description
EINVAL
The value specified by attr does not refer to an initialized thread attribute object.

Example

⁄* CELEBP62 *⁄                                   
⁄* Example using SUSv3 pthread_attr_getguardsize() interface *⁄ 

#define _XOPEN_SOURCE 600

#include <stdio.h>                                                              
#include <stdlib.h>
#include <pthread.h>                                                            
#include <limits.h>                                                            
#include <errno.h>                                                            
                                                                                
                                                                                
int main(void) 
{                                                                               
   pthread_attr_t attr;                                                         
   int            rc; 
   size_t         guardsize;

   if (pthread_attr_init(&attr) == -1) {                                        
      perror("error in pthread_attr_init");                                     
      exit(1);                                                                  
   }                                                                            
                                                                                
   printf("Set guardsize to value of PAGESIZE.\n");
   rc = pthread_attr_setguardsize(&attr, PAGESIZE);
   if (rc != 0) {                                           
      printf("pthread_attr_setguardsize returned: %d\n", rc); 
      printf("Error: %d, Errno_Jr: %08x\n", errno, __errno2());
      exit(2);                                                                  
   } else {
      printf("Set guardsize is %d\n", PAGESIZE);
   }

   rc = pthread_attr_getguardsize(&attr, &guardsize);
   if (rc != 0) {                                           
      printf("pthread_attr_getguardsize returned: %d\n", rc); 
      printf("Error: %d, Errno_Jr: %08x\n", errno, __errno2());
      exit(3);                                                                  
   } else {
      printf("Retrieved guardsize is %d\n", guardsize);
   }
                                                                                
   rc = pthread_attr_destroy(&attr);
   if (rc != 0) {                                     
      perror("error in pthread_attr_destroy");                                  
      exit(4);                                                                  
   }                                                                            

   exit(0);                                                                     
}                                                                               

Related information