From: Eli Zaretskii <eliz@gnu.org>
To: 813gan <813gan@protonmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Threads vs url-http
Date: Mon, 30 Sep 2024 15:22:00 +0300 [thread overview]
Message-ID: <86r0912uxj.fsf@gnu.org> (raw)
In-Reply-To: <UgdWoRkf0HbyGdpZ6Z1jEmQKtWD-ID9LWWdmw8ceFAZXmdURYu9iMzI1HUA3M5BnihGLlu55dD0cOZZK0J1K4-7buOT69iaXO_9WRG5_wuk=@protonmail.com> (message from 813gan on Sun, 29 Sep 2024 23:53:44 +0000)
> Date: Sun, 29 Sep 2024 23:53:44 +0000
> From: 813gan <813gan@protonmail.com>
> Cc: emacs-devel@gnu.org
>
> (defun wiki-read--url-retrieve (url)
> "Wrapper around url-http that download `URL' without blocking thread."
> (let* ((parsed-url (if (url-p url) url (url-generic-parse-url url)))
> (buf nil)
> (cb (lambda (&rest _) (setq buf (current-buffer)) )) )
> (url-https parsed-url cb nil)
> (while (not buf) (thread-yield))
> buf))
> (make-thread (apply 'wiki-read--url-retrieve "https://google.com" nil))
>
> Why thread-yield don't unblock this?
make-thread needs a function as its first argument. But you pass it
the value returned by 'apply', which is not a function at all. So
what happens here, I think, is this:
. Emacs invokes 'apply' to evaluate the argument of make-thread
. 'apply' invokes your wiki-read--url-retrieve function
. the function runs in the main thread, not in the thread started by
make-thread (which is not even called, because the code is stuck
in 'apply', see below)
. after url-https returns (which it does immediately), the code
immediately enters the while-loop, where it calls thread-yield
. because there's only one running thread, thread-yield grabs the
global lock immediately after releasing it, and the loop keeps
looping
. because the program loops continuously, it doesn't let url-https
read from the network process (since Emacs only does that when it
is idle)
. so the output of the network sub-process is never read, and so the
sub-process never ends, and so the callback is never called, and
the loop never ends
next prev parent reply other threads:[~2024-09-30 12:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 0:28 Threads vs url-http 813gan
2024-09-29 5:26 ` Eli Zaretskii
2024-09-29 23:53 ` 813gan
2024-09-30 7:38 ` Michael Albinus
2024-09-30 12:22 ` Eli Zaretskii [this message]
2024-10-06 15:06 ` 813gan
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86r0912uxj.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=813gan@protonmail.com \
--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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).