Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 8
Push a function onto a thread's cancellation-cleanup stack
#include <pthread.h>
void pthread_cleanup_push( void (routine)(void*),
void* arg );
- routine
- The handler that you want to push onto the thread's stack.
- arg
- A pointer to whatever data you want to pass to the function when it's
called.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The pthread_cleanup_push() function pushes the given
cancellation-cleanup handler routine onto the calling thread's
cancellation-cleanup stack.
The cancellation-cleanup handler is popped from the stack and invoked
with argument arg when the thread:
|
The pthread_cleanup_push() macro expands to a few lines of code
that start with an opening brace ({), but don't have a matching
closing brace (}).
You must pair pthread_cleanup_push() with
pthread_cleanup_pop() within the same lexical scope. |
Use a cancellation cleanup handler
to free resources, such as a mutex, when a thread is terminated:
#include <pthread.h>
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
void unlock( void * arg )
{
pthread_mutex_unlock( &lock );
}
void * function( void * arg )
{
while( 1 )
{
pthread_mutex_lock( &lock );
pthread_cleanup_push( &unlock, NULL );
/*
Any of the possible cancellation points could
go here.
*/
pthread_testcancel();
pthread_cleanup_pop( 1 );
}
}
POSIX 1003.1 THR
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
pthread_cleanup_pop(),
pthread_cancel(),
pthread_exit()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 181
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/p/pthread_cleanup_push.html on line 181