pthread_getattr_np - get attributes of thread
#include <pthread.h> int pthread_getattr_np(pthread_t t, pthread_attr_t *attr);
The pthread_getattr_np() function allocates and initializes a thread attribute object with values representing an existing thread. The values of the fields in the pthread_attr_t structure are usually the same as those provided during the creation of thread by using the pthread_create() function or the thr_create() function. However, the following factors occur:
Stack address is often different due to memory alignment or other platform requirements
The schedule inheritance will always match the default value
The detach or daemon states of a thread may have changed after the thread gets created
Some of these values are subject to change. The pthread_getattr_np() function returns a snapshot of the current state. The thread attributes object returned as attr, is intended for use with the various pthread_attr_get*() functions to extract individual pieces of information such as the stack address. For example, the pthread_attr_getstackaddr() function. The caller is responsible for freeing the memory allocated for attr by calling the pthread_attr_destroy() function.
If successful, the pthread_getattr_np() function returns 0. Otherwise, an error number is returned to indicate the error. It is not an error for the target thread to be a zombie thread.
The pthread_getattr_np() function will fail if:
One or more attributes of thread could not be determined
attr is NULL
The value specified by a thread does not refer to an existing thread
The following is an example that shows how to retrieve a thread's current stack address and size.
/* cc thisfile.c */ # include <pthread.h> # include <stdio.h> int main(int argc, char *argv[]) { pthread_attr_t attr; size_t stksize; void *stkaddr; (void) pthread_getattr_np(pthread_self(), &attr); (void) pthread_attr_getstack(&attr, &stkaddr, &stksize); (void) pthread_attr_destroy(&attr); printf("Stack Address = %p\n", stkaddr); printf("Stack Size = %zu\n", stksize); return (0); }
See attributes(7) for descriptions of the following attributes:
|
pthread_attr_init(3C), pthread_attr_destroy(3C), threads(7), attributes(7), standards(7)