From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Threads vs url-http Date: Sun, 29 Sep 2024 08:26:19 +0300 Message-ID: <8634lj58uc.fsf@gnu.org> References: <3GKP9PAUIwZh8IYYiDahnaeVDrY2O7V_LkjMJ_EcOfSz0ltAUheLQ47o9l8VIm0-8vGVQpKuFMjq2qLiHVN3BIeLKx_AbaacMBQbfvR9_cs=@protonmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19366"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: 813gan <813gan@protonmail.com> Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 29 07:27:19 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sumSk-0004sq-4f for ged-emacs-devel@m.gmane-mx.org; Sun, 29 Sep 2024 07:27:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sumRt-0007R8-3F; Sun, 29 Sep 2024 01:26:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sumRq-0007Qd-8V for emacs-devel@gnu.org; Sun, 29 Sep 2024 01:26:22 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sumRq-0001v0-00; Sun, 29 Sep 2024 01:26:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=PUVGHUA9mZyVbwDTPwWutOSbw15mLrArnhndX8/1DZY=; b=RMZwFDMTb1TF yU23tKU7CetiJMWExsV+x6i/vWH1R3s2T/XWrFRazmLOTpFNuAcBv9yTvLqsxHkti+z17vZ9C7n2t Tiye4cvzpH3h8bTQVjEnJJ+S9JT84O8z3nmguCrmzdEbZ4N+X/dy8NtA8lDo2xN1pr8+wI0se06a6 gZ7TVtxUJxKRve9lt66w0FCp3wMVCFu+fW3om/2I5vvB6e6f2n/bWdwIfu1GzWALu0+wP/45uJqR5 VZj7YokvMQ+sPPBGuY1Xii/qX8BOiRdPa3FEUoOWUxvD2DrUx7urd2h3W0rLynewF4nep1sPrnM5U 6C9O6R7X9J+w/h02vpMR6A==; In-Reply-To: <3GKP9PAUIwZh8IYYiDahnaeVDrY2O7V_LkjMJ_EcOfSz0ltAUheLQ47o9l8VIm0-8vGVQpKuFMjq2qLiHVN3BIeLKx_AbaacMBQbfvR9_cs=@protonmail.com> (message from 813gan on Sun, 29 Sep 2024 00:28:36 +0000) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324182 Archived-At: > Date: Sun, 29 Sep 2024 00:28:36 +0000 > From: 813gan <813gan@protonmail.com> > > (require 'url-http) > (require 'url-parse) > (defun url-retrieve-thread (url) > "Wrapper around url-http that download `URL' without blocking main thread." > (let* ((parsed-url (if (url-p url) url (url-generic-parse-url url))) > (mut (make-mutex)) > (cond-var (make-condition-variable mut)) > (buf nil) > (cb (lambda (&rest _) (setq buf (current-buffer)) (with-mutex mut (condition-notify cond-var)) )) ) > (url-http parsed-url cb nil) > (with-mutex mut > (condition-wait cond-var) ) > buf)) > > Idea was to call it from thread. In most trivial case: > (make-thread (apply 'url-retrieve-thread "http://example.com" nil)) You are waiting on a condvar in the same thread which should notify the condvar, don't you? The callback passed to url-http will be called in the context of the same thread in which url-http was called, but that thread is meanwhile blocked in the condition-wait you call after url-http. AFAIU your intent, you should wait on the condvar in the main thread, not in the thread which calls url-http. > It makes Emacs unresponsive (even C-g does not work). Yes, because it's deadlock: a thread is waiting in a condvar which no other thread will call.