unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* multi-threaded Emacs
@ 2008-11-29 13:32 Giuseppe Scrivano
  2008-11-29 20:26 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 89+ messages in thread
From: Giuseppe Scrivano @ 2008-11-29 13:32 UTC (permalink / raw)
  To: emacs-devel

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

Hello,

I attached a small patch that enables basic threads in Emacs; it is just
a proof of concept and not usable yet, my goal was the execution of the
elisp code I included at the bottom.

In the new file thread.c these functions are defined:

(create-thread) 
(with-thread id '(code))
(kill-thread id)

The first one creates a suspended thread that is waiting for requests.
These requests are done by with-thread that allows the execution of
'(code) on the specified thread.  `kill-thread' is used to terminate a
thread execution by its id.

It is a prototype and the code is not very clean, still a lot of work
must be done in order to have working threads, but I think that have a
multi-threaded Emacs worths this effort.

My idea is to share global variables among threads while local bindings
are done locally to threads.

I haven't well investigated all problems that will raise using threads
in Emacs, the first one that come to my attention is the garbage
collector and at the moment I simply disable GC while there are running
threads.


The following elisp code can be used now, it is not safe as the new
thread id is not freed after it is used:

(progn
  (setq i 0)
  (setq j 0)
  (with-thread (create-thread) '(while (< i 20)
                                  (sleep-for 0.2)
                                  (print "hello")
                                  (setq i (1+ i))))
  
  (while (< j 20)
    (print "world")
    (sleep-for 0.25)
    (setq j (1+ j))))



`with-thread' allows to use the same thread multiple times like:

(with-thread foo '(do-something-complex))
(with-thread bar '(do-another-complex-thing))
(with-thread foo '(do-another-complex-thing))

The third call will block the calling thread until `foo' has completed
its previous execution.

What do you think about?


Regards,
Giuseppe



[-- Attachment #2: emacs_multithread.diff.gz --]
[-- Type: application/octet-stream, Size: 12001 bytes --]

^ permalink raw reply	[flat|nested] 89+ messages in thread
* Re[2]: multi-threaded Emacs
@ 2008-12-03  7:59 ak70
  2008-12-04  8:45 ` Richard M Stallman
  2008-12-04 13:21 ` Stefan Monnier
  0 siblings, 2 replies; 89+ messages in thread
From: ak70 @ 2008-12-03  7:59 UTC (permalink / raw)
  To: Giuseppe Scrivano; +Cc: rms@gnu.org, emacs-devel@gnu.org

Hi, guys. I have a generic user-level thread library on Linux. Maybe it can help.
The thread system is called SMASH developed by Kurt Debattista in 2001 as his master study in University of Malta. 
It uses the two level scheduling model, i.e. we have m user level threads running on top of n kernel threads. If you guys are interested,
I can send you the thesis about it( it is a pdf file of size 1Mb). 
A few month ago, I obtained the permission from Kurt to release it under GPL. I did some work on it too for my undergraduate study.
The problems:
1. It is platform dependent. Kurt and I used some x86 assembly language to implement spin locks and lock-free algorithms.
2. It lacks some common features that you would expect in a thread library. For example it has no thread id and when a user-level terminates,
the thread structure will not be destroyed. This is however done on purpose, because our  supervisor argued that SMASH should be at the lowest
level so that any fancy(or not so fancy) features should be implemented by other libraries built on top of it.
3. Since it is developed as a academic project, a lot of decisions were made in favor of our study, not production use.

I think it is a good starting point, but it is not for immediate use. So what you guys think? Are you interested?
> -----Original Message-----
> From: Giuseppe Scrivano <gscrivano@gnu.org>
> To: Stefan Monnier <monnier@IRO.UMontreal.CA>
> Cc: rms@gnu.org, emacs-devel@gnu.org
> Date: 12/02/08 23:41
> Subject: Re: multi-threaded Emacs
> 
> Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> 
> > I rarely use multiple terminals, and when I use them, the current
> > restrictions are mostly bearable.  OTOH I very often would like to keep
> > using my Emacs while it's byte-compiling some files, or while Gnus is
> > fetching some newsgroup.
> 
> This is exactly the problem I had when I first thought of threads.
> 
> Do you think we can solve it (at least partially) using a concurrent
> model?
> 
> Thanks,
> Giuseppe





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

end of thread, other threads:[~2008-12-13  3:08 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-29 13:32 multi-threaded Emacs Giuseppe Scrivano
2008-11-29 20:26 ` Stefan Monnier
2008-11-29 21:01   ` Giuseppe Scrivano
2008-11-29 22:21     ` Stefan Monnier
2008-11-30 11:35       ` Giuseppe Scrivano
2008-11-30 21:46         ` Stefan Monnier
2008-11-30 22:25           ` Giuseppe Scrivano
2008-11-30 23:03             ` Stefan Monnier
2008-11-30 23:30               ` Giuseppe Scrivano
2008-12-01  3:37                 ` Stefan Monnier
2008-12-06 22:50           ` Tom Tromey
2008-12-07  3:31             ` Stefan Monnier
2008-11-29 22:06   ` Tom Tromey
2008-11-30 16:43 ` Richard M Stallman
2008-11-30 17:34   ` Giuseppe Scrivano
2008-11-30 21:51     ` Stefan Monnier
2008-11-30 22:10       ` Giuseppe Scrivano
2008-11-30 22:20     ` Miles Bader
2008-11-30 23:09       ` Stefan Monnier
2008-11-30 23:09       ` Giuseppe Scrivano
2008-12-01  0:10         ` Chetan Pandya
2008-12-01  3:55         ` Stefan Monnier
2008-12-01 14:06     ` Richard M Stallman
2008-12-01 18:57       ` Giuseppe Scrivano
2008-12-01 20:34         ` Stefan Monnier
2008-12-01 22:41           ` joakim
2008-12-02 16:02         ` Richard M Stallman
2008-12-02 22:22           ` Stefan Monnier
2008-12-02 22:41             ` Giuseppe Scrivano
2008-12-03  2:17               ` Stefan Monnier
2008-12-03 18:26                 ` Giuseppe Scrivano
2008-12-03 20:14                   ` Stefan Monnier
2008-12-05  2:59                     ` Richard M Stallman
2008-12-05  7:40                       ` Giuseppe Scrivano
2008-12-05  8:20                         ` Miles Bader
2008-12-05  9:42                           ` Paul R
2008-12-05 10:10                             ` Eli Zaretskii
2008-12-05 10:35                               ` Paul R
2008-12-05 11:02                           ` Helmut Eller
2008-12-05 15:39                             ` Stefan Monnier
2008-12-05 16:22                             ` Ted Zlatanov
2008-12-05 16:57                             ` Tom Tromey
2008-12-06  4:41                               ` Miles Bader
2008-12-06  7:44                               ` Helmut Eller
2008-12-06 22:31                                 ` Stefan Monnier
2008-12-06  8:30                         ` Richard M Stallman
2008-12-05 15:36                       ` Stefan Monnier
2008-12-06 19:25                         ` Richard M Stallman
2008-12-06 22:41                           ` Stefan Monnier
2008-12-06 23:41                             ` Giuseppe Scrivano
2008-12-07 20:51                               ` Stefan Monnier
2008-12-07 23:51                                 ` Giuseppe Scrivano
2008-12-08  3:06                                   ` Chetan Pandya
2008-12-08 15:50                                   ` Stefan Monnier
2008-12-07 16:02                             ` Richard M Stallman
2008-12-07 20:52                               ` Stefan Monnier
2008-12-07 16:15                           ` Giuseppe Scrivano
2008-12-08 18:26                             ` Richard M Stallman
2008-12-08 19:49                               ` Giuseppe Scrivano
2008-12-09  2:15                                 ` dhruva
2008-12-09  2:49                                   ` Stephen J. Turnbull
2008-12-09  2:53                                     ` dhruva
2008-12-09  9:36                                     ` Andreas Schwab
2008-12-09 17:26                                 ` Richard M Stallman
2008-12-09 19:10                                   ` Giuseppe Scrivano
2008-12-10 18:18                                     ` Richard M Stallman
2008-12-10 18:18                                     ` Richard M Stallman
2008-12-09 19:40                                   ` Stefan Monnier
2008-12-10 18:18                                     ` Richard M Stallman
2008-12-11  1:59                                       ` Stefan Monnier
2008-12-11 14:41                                         ` Ted Zlatanov
2008-12-11 18:30                                           ` Stefan Monnier
2008-12-11 18:42                                             ` Ted Zlatanov
2008-12-11 19:01                                               ` Paul R
2008-12-11 20:53                                               ` Stefan Monnier
2008-12-12 19:03                                                 ` Giuseppe Scrivano
2008-12-13  3:08                                                   ` Stefan Monnier
2008-12-11 19:07                                         ` Paul R
2008-12-11 20:54                                           ` Stefan Monnier
2008-12-05  2:59                   ` Richard M Stallman
2008-12-05 15:40                     ` Stefan Monnier
2008-12-02 23:10             ` Florian Beck
2008-11-30 22:17   ` Miles Bader
2008-11-30 16:44 ` Richard M Stallman
  -- strict thread matches above, loose matches on Subject: below --
2008-12-03  7:59 Re[2]: " ak70
2008-12-04  8:45 ` Richard M Stallman
     [not found]   ` <87prk8mhg9.fsf@vanilla.net.mt>
     [not found]     ` <E1L8ZUB-0002x3-VT@fencepost.gnu.org>
2008-12-05 13:27       ` Li Lin
     [not found]         ` <87prk64ilv.fsf@vanilla.net.mt>
2008-12-05 18:37           ` Giuseppe Scrivano
2008-12-06 21:58             ` Magnus Henoch
2008-12-04 13:21 ` Stefan Monnier

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