pthread_attr_setguardsize() - Set 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_setguardsize(pthread_attr_t *attr, size_t guardsize);

General description

pthread_attr_setguardsize() sets the guardsize attribute in attr using the value of guardsize.

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

This function stores the guardsize attribute in the thread attribute object for subsequent calls to pthread_attr_getguardsize(), but no further action is taken. The guardsize attribute is ignored during thread creation.

Note:

The Single UNIX Specification, Version 3 expects a guard area of at least guardsize bytes, but permits the rounding of guardsize to a multiple of the system variable, PAGESIZE. Stack management in z/OS® UNIX sets a guard area of PAGESIZE in 31-bit applications and of (PAGESIZE * PAGESIZE) bytes in AMODE64. These values are the default for the guard size attribute. Requests for larger guard areas will fail with EINVAL.

A zero guardsize requests that no guard area be provided. However, z/OS UNIX stack management requires a guard area. Therefore, this request cannot be satisfied, although pthread_attr_setguardsize() will tolerate a guardsize of zero.

Returned value

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

Error Code
Description
EINVAL
The parameter guardsize is not valid or the value specified by attr does not refer to an initialized thread attribute object.

Example

⁄* CELEBP66 *⁄                                   
⁄* Example using SUSv3 pthread_attr_setguardsize() 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; 

   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_destroy(&attr);
   if (rc != 0) {                                     
      perror("error in pthread_attr_destroy");                                  
      exit(3);                                                                  
   }                                                                            

   exit(0);                                                                     
}                                                                               

Related information