Skip to content

Commit dadd899

Browse files
author
Vladimir Kotal
committed
atfork caveats
1 parent 8f2a6ab commit dadd899

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

threads.tex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@
601601

602602
%%%%%
603603

604+
ifdef([[[NOSPELLCHECK]]], [[[
605+
\pdfbookmark[1]{pthread\_atfork}{pthreadatfork}
606+
]]])
607+
604608
\begin{slide}
605609
\sltitle{\funnm{fork}() and POSIX threads}
606610
\prgchars
@@ -645,8 +649,15 @@
645649
child), you will avoid such deadlocks. That is because when locking mutexes in
646650
the \emph{\texttt{pre-fork}} handler, other threads are still running so the
647651
mutexes held by them should be released eventually (usually each thread exits a
648-
critical section in a short time in well written code). Example:
649-
\example{pthreads/atfork.c}. For more on this topic, see [Butenhof].
652+
critical section in a short time in well written code).
653+
\item This scheme will only work if the \emph{\texttt{pre-fork}} handler
654+
maintains the same locking protocol/ordering as is used in the
655+
application/library. Sometimes that is just not possible due to multiple complex
656+
orderings in place. Very often \funnm{fork}() is called just as a means for
657+
later \funnm{exec}(). In such case the programmer would be better off using
658+
\funnm{posix\_spawn}().
659+
\item Example: \example{pthreads/atfork.c}
660+
\item For more on this topic, see [Butenhof].
650661
\item See page \pageref{MUTEXES} on why mutexes locked in other threads on
651662
\funnm{fork}() stay locked forever.
652663
\end{itemize}

0 commit comments

Comments
 (0)