Declares handlers to be called when the process forks a child.
This routine is for Digital UNIX systems only.
pthread_atfork(
prepare,
parent,
child );
Argument Data Type Access
prepare Handler read
parent Handler read
child Handler read
#includeint pthread_atfork ( void (*prepare)(void), void (*parent)(void), void (*child)(void) );
Mutex locks might be held by threads that no longer exist in a child process and any associated state might be inconsistent. The program can avoid this problem by calling pthread_atfork() to provide code that acquires and releases locks critical to the child process. For example, if your library uses a mutex named "my_mutex", you might provide pthread_atfork handlers like:
void my_prepare(void)
{
pthread_mutex_lock(&my_mutex);
}
void my_parent(void)
{
pthread_mutex_unlock(&my_mutex);
}
void my_child(void)
{
pthread_mutex_unlock(&my_mutex);
/* Reinitialize state that doesn't apply...like heap owned */
/* by other threads */
}
{
.
.
.
pthread_atfork(my_prepare, my_parent, my_child);
.
.
fork();
}
Return Description
0 Successful completion.
[ENOMEM] Insufficient table space exists to record the fork
handler addresses.