diff options
| author | Eli Zaretskii | 2019-04-20 10:21:02 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2019-04-20 10:21:02 +0300 |
| commit | f90a3360d8c724d61ff89a2e788542a4ff6cb352 (patch) | |
| tree | 434345009b0eef9981ca91c9abd5e416b98946d8 | |
| parent | 037970f1af6c87767501ac6d46c50abe9d3f44e0 (diff) | |
| download | emacs-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.texi | 20 |
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 | |||
| 1834 | arrived. | 1834 | arrived. |
| 1835 | @end defun | 1835 | @end defun |
| 1836 | 1836 | ||
| 1837 | If a connection from a process contains buffered data, | ||
| 1838 | @code{accept-process-output} can return non-@code{nil} even after the | ||
| 1839 | process 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 | ||
| 1848 | will often read all output from @var{process}, it has a race condition | ||
| 1849 | and can miss some output if @code{process-live-p} returns @code{nil} | ||
| 1850 | while the connection still contains data. Better is to write the loop | ||
| 1851 | like 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 |