Книга: Programming with POSIX® Threads

9.3.9 Fork handlers

9.3.9 Fork handlers

Pthreads provides some new functions to help the new threaded environment to coexist with the traditional process-based UNIX environment. Creation of a child process by copying the full address space, for example, causes problems for threaded applications because the fork call is asynchronous with respect to other threads in the process.

pthread_atfork

int pthread_atfork (

void (*prepare)(void),

void (*parent)(void),

void (*child)(void));

Define "fork handlers" that are run when the process creates a child process. Allows protection of synchronization objects and shared data in the child process (which is otherwise difficult to control).

References: 6.1.1

Headers: <unistd.h>*[10]

Errors: [ENOMEM] insufficient space to record the handlers.

Hint: All resources needed by child must be protected.

Оглавление книги


Генерация: 0.342. Запросов К БД/Cache: 0 / 3
поделиться
Вверх Вниз