Manual Page Search Parameters

PTHREAD_ATTR_GET_NP(3) Library Functions Manual PTHREAD_ATTR_GET_NP(3)

pthread_attr_get_npget attributes of an existing thread

POSIX Threads Library (libpthread, -lpthread)

#include <pthread_np.h>

int
pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst);

The () function is used to retrieve the attributes of the specified thread into an existing pthread_attr_t structure. The attributes' values are the current ones for the target thread, except for the stack top address if not properly aligned for the architecture, since in this case its value has been adjusted internally before use.

Argument dst must be a pointer to a valid attributes object (it was initialized at some point by pthread_attr_init(3) and was not destroyed since then). After a successful call to (), the individual attributes' values can be retrieved as usual via the corresponding accessor functions as documented in pthread_attr(3). After a failed call to pthread_attr_get_np(), the object pointed to by dst is left unmodified, and can continue to be used as if the failed call never happened.

If successful, pthread_attr_get_np() function returns 0. Otherwise, an error number is returned to indicate the error.

This function retrieves the stack size of the thread specified by the pid argument:

size_t
my_thread_stack_size(pthread_t tid)
{
	pthread_attr_t attr;
	size_t size;

	pthread_attr_init(&attr);
	pthread_attr_get_np(tid, &attr);
	pthread_attr_getstacksize(&attr, &size);
	pthread_attr_destroy(&attr);
	return (size);
}

The pthread_attr_get_np() function will fail if:

[]
One of the arguments has an invalid value.
[]
No thread could be found corresponding to that specified by the given thread ID.
[]
There was not enough memory to allocate additional storage needed by the attributes object's implementation.

pthread_attr(3), pthread_attr_destroy(3), pthread_attr_getdetachstate(3), pthread_attr_getinheritsched(3), pthread_attr_getschedparam(3), pthread_attr_getschedpolicy(3), pthread_attr_getscope(3), pthread_attr_getstack(3), pthread_attr_getstackaddr(3), pthread_attr_getstacksize(3), pthread_attr_init(3), pthread_np(3)

The pthread_attr_get_np() function and this manual page were written by Alexey Zelkin <phantom@FreeBSD.org>, and the latter was revised by
Olivier Certner <olce@FreeBSD.org>.

January 5, 2024 dev