⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread_atfork.man

📁 linux 下的线程库源码
💻 MAN
字号:
.TH PTHREAD_ATFORK 3 LinuxThreads.SH NAMEpthread_atfork \- register handlers to be called at fork(2) time.SH SYNOPSIS#include <pthread.h>int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));.SH DESCRIPTION!pthread_atfork! registers handler functions to be called just beforeand just after a new process is created with !fork!(2). The |prepare|handler will be called from the parent process, just before the newprocess is created. The |parent| handler will be called from the parentprocess, just before !fork!(2) returns. The |child| handler will becalled from the child process, just before !fork!(2) returns.One or several of the three handlers |prepare|, |parent| and |child|can be given as !NULL!, meaning that no handler needs to be called atthe corresponding point.!pthread_atfork! can be called several times to install several setsof handlers. At !fork!(2) time, the |prepare| handlers are called inLIFO order (last added with !pthread_atfork!, first called before !fork!),while the |parent| and |child| handlers are called in FIFO order(first added, first called).To understand the purpose of !pthread_atfork!, recall that !fork!(2)duplicates the whole memory space, including mutexes in their currentlocking state, but only the calling thread: other threads are notrunning in the child process. Thus, if a mutex is locked by a threadother than the thread calling !fork!, that mutex will remain lockedforever in the child process, possibly blocking the execution of thechild process. To avoid this, install handlers with !pthread_atfork!as follows: the |prepare| handler locks the global mutexes (in lockingorder), and the |parent| and |child| handlers unlock them (inreverse order). Alternatively, |prepare| and |parent| can be set to!NULL! and |child| to a function that calls !pthread_mutex_init! onthe global mutexes..SH "RETURN VALUE"!pthread_atfork! returns 0 on success and a non-zero error code on error..SH ERRORS.TP!ENOMEM!insufficient memory available to register the handlers..SH AUTHORXavier Leroy <Xavier.Leroy@inria.fr>.SH "SEE ALSO"!fork!(2),!pthread_mutex_lock!(3),!pthread_mutex_unlock!(3).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -