help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No thread yield when using synchronous processes?


From: Eli Zaretskii
Subject: Re: No thread yield when using synchronous processes?
Date: Thu, 13 Dec 2018 15:45:34 +0200

> From: Michael Albinus <michael.albinus@gmx.de>
> Date: Thu, 13 Dec 2018 10:47:32 +0100
> Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> 
> > it seems like Emacs doesn't yield when using synchronous processes:
> >
> > (make-thread (lambda () (call-process "sleep" nil nil nil "5s")))
> >
> > ⇒ Emacs freezes for 5 seconds.
> >
> > Is there a reason for this behavior? The manual claims that Emacs
> > yields when waiting for process output, but that only seems to be the
> > case for asynchronous processes.
> 
> The manual is clear about this: "when waiting for ... process output
> (e.g., during ‘accept-process-output’)". `accept-process-output' is used
> only for asynchronous processes.

Right.  Though perhaps we should say that more explicitly, as "e.g."
could be interpreted like just one example, not necessarily a
representative of a class of examples.

Technically, thread switches happen when Emacs calls 'pselect', which
it does as part of its idle loop.  call-process doesn't enter the idle
loop, it busy-waits until the process exits.  One could think about
calling the idle loop while we wait, but this will have significant
Emacs-wide effects, which need to be considered carefully before we
decide to do it.

(Btw, pedantically, the example above doesn't really _wait_ for
process output, it explicitly discards that output.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]