aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2019-04-20 10:21:02 +0300
committerEli Zaretskii2019-04-20 10:21:02 +0300
commitf90a3360d8c724d61ff89a2e788542a4ff6cb352 (patch)
tree434345009b0eef9981ca91c9abd5e416b98946d8
parent037970f1af6c87767501ac6d46c50abe9d3f44e0 (diff)
downloademacs-f90a3360d8c724d61ff89a2e788542a4ff6cb352.tar.gz
emacs-f90a3360d8c724d61ff89a2e788542a4ff6cb352.zip
Backport doc improvement in ELisp manual
* doc/lispref/processes.texi (Accepting Output): Backport: document how do avoid race conditions while waiting for all of the process's output to arrive.
-rw-r--r--doc/lispref/processes.texi20
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index d2ab518e5eb..7331eb63762 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -1834,6 +1834,26 @@ corresponding connection contains buffered data. The function returns
1834arrived. 1834arrived.
1835@end defun 1835@end defun
1836 1836
1837If a connection from a process contains buffered data,
1838@code{accept-process-output} can return non-@code{nil} even after the
1839process has exited. Therefore, although the following loop:
1840
1841@example
1842;; This loop contains a bug.
1843(while (process-live-p process)
1844 (accept-process-output process))
1845@end example
1846
1847@noindent
1848will often read all output from @var{process}, it has a race condition
1849and can miss some output if @code{process-live-p} returns @code{nil}
1850while the connection still contains data. Better is to write the loop
1851like this:
1852
1853@example
1854(while (accept-process-output process))
1855@end example
1856
1837@node Processes and Threads 1857@node Processes and Threads
1838@subsection Processes and Threads 1858@subsection Processes and Threads
1839@cindex processes, threads 1859@cindex processes, threads