all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: yyoncho <yyoncho@gmail.com>
To: Alexander Miller <alexanderm@web.de>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Questions about throw-on-input
Date: Sun, 10 May 2020 14:11:48 +0300	[thread overview]
Message-ID: <CACCVLQWbQB9pWx+89u=FT1MAmKR9m1CTA5xHHCaLpo-RBgh3jg@mail.gmail.com> (raw)
In-Reply-To: <1e2afa74-a0b3-1d81-7111-2340f381bb9d@web.de>

[-- Attachment #1: Type: text/plain, Size: 1837 bytes --]

Thank you, Alexander.

I was planning to span a new thread but the approach with the queue might
be a better fit for us. Do you have the numbers for what will yield better
performance - checking input-pending and then thread-yield or directly
calling thread-yield?

Ivan

On Sat, May 9, 2020 at 4:09 PM Alexander Miller <alexanderm@web.de> wrote:

> [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
>   worker
>   (make-thread
>    (lambda ()
>      (while t
>        (while worker-queue
>          (let* ((work-unit (pop worker-queue))
>                 (fn (car work-unit))
>                 (args (cdr work-unit)))
>            (apply fn args)
>            (thread-yield)))
>        (with-mutex worker-mutex
>          (condition-wait worker-cond-var))))
>    "*WORKER*"))
>
> (setf worker-timer
>        (run-with-idle-timer
>         1 t (lambda ()
>               (when worker-queue
>                 (with-mutex worker-mutex
>                   (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.
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2560 bytes --]

  reply	other threads:[~2020-05-10 11:11 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 13:09 Questions about throw-on-input Alexander Miller
2020-05-10 11:11 ` yyoncho [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-05-10 13:47 Alexander Miller
2020-05-11 14:13 ` Eli Zaretskii
2020-05-11 15:21   ` Stefan Monnier
2020-05-11 16:19     ` Eli Zaretskii
2020-05-11 17:27       ` Stefan Monnier
2020-05-11 17:39         ` Alexander Miller
2020-05-11 18:23           ` Eli Zaretskii
2020-05-11 18:24           ` Stefan Monnier
2020-05-11 19:48             ` Alexander Miller
2020-05-11 20:14               ` Stefan Monnier
2020-05-12 22:33                 ` Alexander Miller
2020-05-13 14:43                   ` Eli Zaretskii
2020-05-13 18:47                     ` Alexander Miller
2020-05-14  8:32                     ` Philipp Stephani
2020-05-14 14:23                       ` Eli Zaretskii
2020-05-14 14:37                         ` Philipp Stephani
2020-05-14 16:56                       ` Drew Adams
2020-05-15  3:21                         ` Richard Stallman
2020-05-15  3:54                           ` Stefan Monnier
2020-05-15  8:19                             ` Arthur Miller
2020-05-15 15:45                               ` Stefan Monnier
2020-05-15 16:46                                 ` Yuan Fu
2020-05-15 17:31                                   ` Stefan Monnier
2020-05-15 17:50                                     ` yyoncho
2020-05-15 18:44                                       ` Alexander Miller
2020-05-15 18:55                                         ` Stefan Monnier
2020-05-15 19:46                                         ` Philipp Stephani
2020-05-15 18:00                                     ` Andrea Corallo
2020-05-15 17:35                                 ` Arthur Miller
2020-05-15 19:47                                 ` chad
2020-05-16 11:29                                   ` Eli Zaretskii
2020-05-12  2:39           ` Daniel Colascione
2020-05-12 14:37             ` Eli Zaretskii
2020-05-11 18:17         ` Eli Zaretskii
2020-05-07  7:31 Ivan Yonchovski
2020-05-07 12:36 ` Eli Zaretskii
2020-05-07 14:28   ` Ivan Yonchovski
2020-05-07 21:11   ` yyoncho
2020-05-08  1:58     ` Stefan Monnier
2020-05-08  4:36       ` yyoncho
2020-05-08  4:43         ` yyoncho
2020-05-12  4:15       ` Michael Heerdegen
2020-05-08 10:41     ` Eli Zaretskii
2020-05-08 11:23       ` Ivan Yonchovski
2020-05-08 11:45         ` Eli Zaretskii
2020-05-08 11:55           ` yyoncho
2020-05-08 14:55         ` Stefan Monnier
2020-05-08 18:04           ` yyoncho
2020-05-07 13:49 ` Stefan Monnier
2020-05-07 15:36   ` Ivan Yonchovski

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='CACCVLQWbQB9pWx+89u=FT1MAmKR9m1CTA5xHHCaLpo-RBgh3jg@mail.gmail.com' \
    --to=yyoncho@gmail.com \
    --cc=alexanderm@web.de \
    --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.