all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-devel@gnu.org
Subject: Re: [RFC] Gnus generalized search, part II
Date: Sat, 22 Apr 2017 12:25:12 -0700	[thread overview]
Message-ID: <87shl01bzb.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 8337d0qxno.fsf@gnu.org

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> On Sat, Apr 22, 2017 at 11:08 AM, Eric Abrahamsen
> <eric@ericabrahamsen.net> wrote:
>> I'm still trying to get a correct mental model of how all this is
>> working. I assume that, if I gather the threads using:
>>
>> (mapc #'thread-join threads)
>>
>> None of the threads ever become the "current thread",
>
> Wouldn't thead-join stop the current thread, and then whichever thread
> runs next (probably one of the ones in `threads') would become the
> current thread?

Ah, of course! Yeesh, this is taking a while to wrap my brain around.

Eli Zaretskii <eliz@gnu.org> writes:

> But what _is_ the right thing?
>
> I asked the question because I really would like to know what would
> you want/expect to be the effect of C-g on the active threads?  It's
> not a rhetoric question.  Can you please humor me?

Okay! Sorry... Basically we're sending search queries to multiple
servers, and using threads to make the external processes asynchronous.
C-g would come into play when one or more of those processes hangs or is
slow, and the user loses patience and wants to quit. The desired result
would be that whichever thread we're currently waiting on gets killed,
and the other threads continue. Ideally there would be a message noting
which search process was abandoned, which is another reason to use
condition-case.

Ugh, this is hurting my brain. Here's the code skeleton:

(let* ((results "")
       (threads
	(mapcar
	 (lambda (thing)
	   (make-thread
	    (lambda ()
	      (let ((proc (start-process name buf thing-program)))
		(accept-process-output proc)
		(with-current-buffer buf
		 (setq results
		       (concat (buffer-string) results)))))))
	 '(thing1 thing2))))
  (mapc #'thread-join threads))

accept-process-output is given no timeout. So when we hit the first
`thread-join', we wait for the first accept-process-output to return
completely, putting all its output in its process buffer. While it's
doing that, output from the second and third thread processes is also
arriving on the wire, but it's being buffered in C code or in the
process itself or in some other special non-Lisp place (I'm making this
part up, I have no idea). Assuming the three processes take the same
amount of time, the second and third `thread-join's should finish very
quickly, because all they have to do is dump their output from wherever
it's being held into their respective process buffers, and then concat
the buffer strings into the result.

Is that actually what happens?

I'm trying to think about what would happen if we looped the
`accept-process-output' on say a half-second timeout. When the first
`thread-join' is called, does it mean all three processes would start
getting half-second opportunities to write process output into their
output buffers? Or would the second and third threads not get to do
their `accept-process-output' calls at all until they were joined?
Here's where I get confused.

Realistically, the user would be unlikely to quit unless one of the
processes was taking a very long time, at which point that would be the
only running thread, and probably the right thing would happen.

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sat, 22 Apr 2017 18:17:47 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>> Cc: emacs-devel@gnu.org
>> 
>> > Is (accept-process-output 0) the same as (accept-process-output
>> > nil)?
>> 
>> Yes.
>
> Sorry, I've misread the code.  Zero means don't wait at all, even if
> process output is not available.

Good to know, thanks. Actually, in a second I'll do a patch to add that
to the docstring, that's useful information.

Eric




  parent reply	other threads:[~2017-04-22 19:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21 21:35 [RFC] Gnus generalized search, part II Eric Abrahamsen
2017-04-22  0:16 ` Andrew Cohen
2017-04-22  5:27   ` Eric Abrahamsen
2017-04-22  8:08     ` Eli Zaretskii
2017-04-22 15:08       ` Eric Abrahamsen
2017-04-22 15:17         ` Eli Zaretskii
2017-04-22 15:25           ` Eli Zaretskii
2017-04-22 19:25           ` Eric Abrahamsen [this message]
2017-04-22 20:06             ` Eli Zaretskii
2017-04-22 22:50               ` Eric Abrahamsen
2017-04-30 17:46                 ` Eric Abrahamsen
2017-04-24 17:17             ` Stephen Leake
2017-04-26  9:42               ` Eli Zaretskii
2017-04-22 16:00         ` Noam Postavsky
2017-04-22  7:50   ` Eli Zaretskii
2017-04-22  8:00     ` Andrew Cohen
2017-04-22 19:53 ` Lars Ingebrigtsen
2017-04-22 20:26   ` Eric Abrahamsen
2017-04-24 20:30   ` Eric Abrahamsen
2017-04-26  4:41     ` Andrew Cohen
2017-04-26  9:21       ` Joakim Jalap
2017-04-26  8:18     ` Andrew Cohen
2017-04-26  8:22     ` Andrew Cohen
2017-04-23 13:48 ` Dan Christensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87shl01bzb.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.