unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Threading IO-bound functions
@ 2016-12-15  4:01 Elias Mårtenson
  2016-12-16 15:26 ` Eli Zaretskii
  2016-12-16 22:05 ` Threading IO-bound functions Ken Raeburn
  0 siblings, 2 replies; 14+ messages in thread
From: Elias Mårtenson @ 2016-12-15  4:01 UTC (permalink / raw)
  To: emacs-devel

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

The number one function that I call that sometimes hang for a significant
amount of time is ‘gnus’. I decided to try running it in a thread, and it
worked surprisingly well. Initial loading of the messages can now be done
in the background.

To prevent myself from running this function more than once at the same
time, I created a wrapper function for this, and I have extracted it into a
macro.

I'd like to have people's opinions on this strategy, and if it might be
reasonable to default ‘gnus’ to do this when run on Emacs versions with
concurrency support.

(defmacro define-background-function-wrapper (bg-function fn)
  (let ((is-loading-sym (intern (concat "*" (symbol-name bg-function)
"-is-loading*"))))
    `(progn
       (defvar ,is-loading-sym nil)
       (defun ,bg-function ()
         (interactive)
         (when ,is-loading-sym
           (message ,(concat (symbol-name fn) " is already loading")))
         (setq ,is-loading-sym t)
         (make-thread (lambda ()
                        (unwind-protect
                            (,fn)
                          (setq ,is-loading-sym nil))))))))

It's invoked like ‘(define-background-function-wrapper bg-gnus gnus)’. This
will then define the function ‘bg-gnus’ that runs ‘gnus‘ in a thread.

Regards,
Elias

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-12-22 17:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-15  4:01 Threading IO-bound functions Elias Mårtenson
2016-12-16 15:26 ` Eli Zaretskii
2016-12-19  3:03   ` Elias Mårtenson
2016-12-19  3:39     ` Eli Zaretskii
2016-12-19  7:06       ` Elias Mårtenson
2016-12-19 17:32         ` Eli Zaretskii
2016-12-19 17:43         ` The event handling thread (was: Threading IO-bound functions) John Wiegley
2016-12-20 16:08           ` Eli Zaretskii
2016-12-21  1:04             ` The event handling thread John Wiegley
2016-12-21 11:05               ` Elias Mårtenson
2016-12-21 17:42                 ` Eli Zaretskii
2016-12-22  3:12                   ` Elias Mårtenson
2016-12-22 17:37                     ` Eli Zaretskii
2016-12-16 22:05 ` Threading IO-bound functions Ken Raeburn

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).