__pthread_atexit_np Subroutine

Purpose

Registers a handler routine to be invoked when the calling thread exits.

Library

Threads library (libpthreads.a)

Syntax

#include <pthread.h>

int __pt_atexit_np (flags, handler_routine, ...)
int flags;
int (*handler_routine) (int, ...);

Description

The __pt_atexit_np subroutine adds the specified handler routine to a stack of handler routines for the calling thread. When the calling thread exits by using the pthread_exit() subroutine, the calling thread's handler routines are removed from the stack, one at a time. These handler routines are invoked after the cleanup routines are called and after the thread-specific data is cleaned up.

The flags parameter must be set to 0. If a nonzero value is specified, the EINVAL error code is returned. The handler function contains a flags parameter and optional parameters. Each handler function is invoked with a single 0 argument. The return value of a handler function must be 0. Nonzero values are reserved for future use.

If a handler routine calls the __pt_atexit_np subroutine to register additional handler routines, the additional routines are pushed onto the stack of handler routines. These additional routines are called when the registering handler routine returns.

If a thread calls exit(), its handler routines are invoked before any other processing takes place, such as calling at-exit routines. In this case, handler routines in other threads are not called unless other threads are canceled by the exiting thread. If a handler calls the pthread_exit() subroutine, the thread exits without causing the process to exit.

If a thread calls the exec() function, the handler routines are not called for any thread.

If a thread calls the fork() function, its handler routines remain registered in the child process.

Note: You cannot remove a handler routine from the stack of registered handler routines.

Parameters

flags
The only allowed value is 0.
handler_routine
Points to the handler routine to be invoked by the thread. The handler routine is invoked with a single 0 argument. The handler routine must return 0. Nonzero values are reserved for future use.

Return values

If successful, the __pt_atexit_np subroutine returns 0. Otherwise, an error number is returned to indicate the error.

Error codes

The __pt_atexit_np subroutine fails if the following error code is returned:

EINVAL
The flags parameter is not 0.