From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alexander Miller Newsgroups: gmane.emacs.devel Subject: Re: Questions about throw-on-input Date: Sat, 9 May 2020 15:09:58 +0200 Message-ID: <1e2afa74-a0b3-1d81-7111-2340f381bb9d@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="56355"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Cc: emacs-devel@gnu.org To: yyoncho@gmail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 09 15:15:27 2020 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 1jXPKA-000EY0-FB for ged-emacs-devel@m.gmane-mx.org; Sat, 09 May 2020 15:15:26 +0200 Original-Received: from localhost ([::1]:46208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXPK8-00084s-OG for ged-emacs-devel@m.gmane-mx.org; Sat, 09 May 2020 09:15:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXPEj-0004yb-RU for emacs-devel@gnu.org; Sat, 09 May 2020 09:09:49 -0400 Original-Received: from mout.web.de ([212.227.15.3]:45045) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXPEh-0006bY-PT for emacs-devel@gnu.org; Sat, 09 May 2020 09:09:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1589029784; bh=6b32LXqUx3H8xJG7K4bSt8YYlz7y35Zc2j8dQ9/JFpw=; h=X-UI-Sender-Class:To:References:Subject:In-Reply-To:Cc:From:Date; b=hHS4mRjHgZrKhGOO2rmwiZw7Owgz26jMcktfrgxGEiK7/B1rGx3XH5HPQWAUmNpuF IOFkWUVumR6axXMWmfC0Yno/vakazZ4pArSq5Ar/S1rtkT/mJiqtfpw4byGEFEQ45e vzz7/0IB36FPiVpr3vtVUoRoPC/Nzj7Oqqw81VWw= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from [192.168.2.105] ([217.241.222.163]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MWeGR-1jdlqN0Cst-00XwYf; Sat, 09 May 2020 15:09:44 +0200 Content-Language: en-US X-Provags-ID: V03:K1:88omzyIzumsyrroJgBXEvAp8PJgthwPz14bHAw6QP4q7BBR0OP8 gPfWUZtZr7fhJ4RJEorzCVZmo4qaEOD9+oUMA1pqHCRQ9wWLyuqxYW9E6KHb3yIvMHKKd8r p1e1tO29XK9b0hyViffDNq3c7kEg4bnqZZLM/2VKfCEO6UAmR7S3Dkgnk1KyWGzW0jJpUbn z2Groi5Fcvb4oEfJjdwKA== X-UI-Out-Filterresults: notjunk:1;V03:K0:JQ8/Jpnpod8=:GdWuSb8mJxGPKvqK8k0iyl 1xIFtiqycquqDrR4yhfgt8+f0lHaSxNY0YhWW+4X2/ar6yVQPcVbpR7VEynjutTsjoVdIbCCR x4+wSmsTVcS3Gkmnqdi7MUtQUURFw6YiP66gXZtBSEVp/WaAut9WMKWU6EMQgQyeu28N9ZKWn qF2C+lQZRN5E2SJhDL4AiH6GjpoXSB3oDOJCsgXMMkydx9pYWolme+RAEA9MkHWah2H3yH8y3 PlYb7ohALn4ZfiWR9VY/8uZiuFUjMMlUzeVXVvkUIAR+lv8ogiyLhjnUQxmREALTPK96yj+eL nB4kyqspgaGTfzKHphu2Mq/Lwd9pGid9YwJ3rAhR2RkjFOPp0IeowmJXG5YdniMd455wtczMT yqXZcDRR+Nkiy6/VGgD7p5fwq1igpdN3Sn25z0luq/dAMTwpjSMfLxXuQEgAzN0+8lEV/pQvj rRIueIyr1yz8q+ZvGpw8WSaXaJ0GElCuHpUUcK8yNK8Jr7rHJWjDvbA1rRi7MGpwLyDMb0Wyk 04zDlUvAZsItShq1RE94WfcNrpYkJwu1854irt7vTNOOngLZ0I8DNkpQl3xaxeh7mZLYC+art QuL69o/oIM2oWjrV0X7F6966kIOwhJg3NZF+tsYJV9nxxNGgyUt2BUu/r88Cjm15i84qVGcCY OMaOy++7wqe77Y+75xcnkOrg2wwASL20LM32lF54R3puipDI0q8JlsUfzjLK6uALvmmrgbONq fv0dVhcFrQDecbUn/6FI5AM27/qBJo18H1szeq16mfIF1Oury5yWZ44PdAzyKb8bgwf9frdL Received-SPF: pass client-ip=212.227.15.3; envelope-from=alexanderm@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/09 09:09:44 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:249420 Archived-At: [I had to copy the In-Reply-To header from the page source because the reply-to button wouldn't set it, so let's hope I'm doing this right.] Incidentally I have recently been playing around with a similar idea - to use a worker thread to split and run long tasks in the background. Here's what I came up with so far: (defconst worker-mutex (make-mutex "*WORKER MUTEX*")) (defconst worker-cond-var (make-condition-variable worker-mutex)) (defvar worker-queue (list)) (setf =C2=A0worker =C2=A0(make-thread =C2=A0 (lambda () =C2=A0=C2=A0=C2=A0 (while t =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (while worker-queue =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (let* ((work-unit (pop worker-= queue)) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (fn (car work-unit)) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (args (cdr work-unit))) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (apply fn args) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (thread-yield))) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (with-mutex worker-mutex =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (condition-wait worker-cond-va= r)))) =C2=A0 "*WORKER*")) (setf worker-timer =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (run-with-idle-timer =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1 t (lambda () =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = (when worker-queue =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (with-mutex worker-mutex =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (condition-notify worker-cond-var)))))) (push (list #'shell-command-to-string "notify-send 'Hello' 'World!'") worker-queue) (push (list #'message "Hello %s!" "World") worker-queue) (push (list #'call-interactively #'treemacs) worker-queue) Get enough thread-yield or input-pending checks into the work the thread is doing and you might just be able to get around blocking the UI despite having plenty to do.