用 Thread 实现的并行支持已经合并进了 master
:
已提交 04:54PM - 10 Dec 16 UTC
Merge branch 'test-concurrency'
* src/thread.c:
* src/thread.h:
* src/systhread… .c:
* src/systhread.h: New files.
* src/xgselect.c (xg_select): Avoid using SAFE_NALLOCA and use
xnmalloc unconditionally.
* src/window.c (struct save_window_data): Rename current_buffer to
f_current_buffer.
* src/w32proc.c (sys_select): Change the function signature to
closer fit 'pselect' on Posix hosts.
* src/search.c:
* src/regex.h: Convert some globals to macros that reference
thread-specific values.
* src/process.c (pset_thread, add_non_keyboard_read_fd)
(add_process_read_fd, add_non_blocking_write_fd)
(recompute_input_desc, compute_input_wait_mask)
(compute_non_process_wait_mask, compute_non_keyboard_wait_mask)
(compute_write_mask, clear_waiting_thread_info)
(update_processes_for_thread_death, Fset_process_thread)
(Fprocess_thread): New functions.
(enum fd_bits): New enumeration.
(fd_callback_data): Add 'thread' and 'waiting_thread', rename
'condition' to 'flags'.
(set_process_filter_masks, create_process, create_pty)
(Fmake_serial_process, finish_after_tls_connection)
(connect_network_socket, deactivate_process)
(server_accept_connection, wait_reading_process_output)
(Fcontinue_process, Fstop_process, keyboard_bit_set)
(add_timer_wait_descriptor, add_keyboard_wait_descriptor)
(delete_keyboard_wait_descriptor): Use the new functions instead
of manipulating fd flags and masks directly.
(syms_of_process): Defsubr the new primitives.
* src/print.c (print_object): Print threads, mutexes, and
conditional variables.
* src/lisp.h (enum pvec_type): New values PVEC_THREAD, PVEC_MUTEX,
and PVEC_CONDVAR.
(XTHREAD, XMUTEX, XCONDVAR, THREADP, MUTEXP, CONDVARP)
(CHECK_THREAD, CHECK_MUTEX, CHECK_CONDVAR): New inline functions.
(XSETTHREAD, XSETMUTEX, XSETCONDVAR): New macros.
(struct handler): Add back byte_stack. Rename lisp_eval_depth to
f_lisp_eval_depth.
* src/eval.c (specpdl_kind, specpdl_arg, do_specbind)
(rebind_for_thread_switch, do_one_unbind)
(unbind_for_thread_switch): New functions.
(init_eval): 'handlerlist' is not malloc'ed.
(specbind): Call do_specbind.
(unbind_to): Call do_one_unbind.
(mark_specpdl): Accept 2 arguments.
(mark_specpdl): Mark the saved value in a let-binding.
* src/emacs.c (main): Call init_threads_once, init_threads, and
syms_of_threads.
* src/data.c (Ftype_of): Support thread, mutex, and condvar
objects.
(Fthreadp, Fmutexp, Fcondition_variable_p): New functions.
(syms_of_data): DEFSYM and defsubr new symbols and primitives.
* src/bytecode.c (struct byte_stack, FETCH, CHECK_RANGE)
(BYTE_CODE_QUIT): Add back.
(exec_byte_code): Add back byte stack manipulation.
* src/alloc.c (cleanup_vector): Handle threads, mutexes, and
conditional variables.
(mark_stack): Now extern; accept additional argument 'bottom'.
(flush_stack_call_func): New function.
(garbage_collect_1): Call mark_threads and unmark_threads. Don't
mark handlers.
* src/.gdbinit (xbytecode): Add back.
* test/src/thread-tests.el: New tests.
* test/src/data-tests.el (binding-test-manual)
(binding-test-setq-default, binding-test-makunbound)
(binding-test-defvar-bool, binding-test-defvar-int)
(binding-test-set-constant-t, binding-test-set-constant-nil)
(binding-test-set-constant-keyword)
(binding-test-set-constant-nil): New tests.
* doc/lispref/processes.texi (Processes and Threads): New
subsection.
* doc/lispref/threads.texi: New file
* doc/lispref/elisp.texi (Top): Include it.
* doc/lispref/objects.texi (Thread Type, Mutex Type)
(Condition Variable Type): New subsections.
(Type Predicates): Add thread-related predicates.
* doc/lispref/objects.texi (Editing Types):
* doc/lispref/elisp.texi (Top): Update higher-level menus.
* etc/NEWS: Mention concurrency features.
News (source ):
** Emacs now provides a limited form of concurrency with Lisp threads.
Concurrency in Emacs Lisp is “mostly cooperative”, meaning that
Emacs will only switch execution between threads at well-defined
times: when Emacs waits for input, during blocking operations related
to threads (such as mutex locking), or when the current thread
explicitly yields. Global variables are shared among all threads, but
a ‘let’ binding is thread-local. Each thread also has its own current
buffer and its own match data.
See the chapter “Threads” in the ELisp manual for full documentation
of these facilities.
3 个赞
LdBeth
2016 年12 月 24 日 08:41
2
哦哦,支持多线程了吗。这样就看gnus就不会卡了吧。有编译成功的吗。
LdBeth:
有编译成功的吗。
编译应该没问题吧,我的 Emacs 就是昨天编译自最新的 master 分支。
(emacs-version)
⇒ "GNU Emacs 26.0.50.11 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
of 2016-12-23"
emacs-repository-version
⇒ "a978d300a3faf58ee6e94ba57f764ca99a9ec308"
emacs开发还挺活跃的吗?现在核心开发几个人呀?
感觉Emacs扩展没有跟上Emacs的步伐啊
今天编译了一下上面提到支持多线程的emacs版本。编译完运行发现spacemacs会报错。
(emacs-version)
"GNU Emacs 26.0.50.1 (x86_64-apple-darwin16.3.0, NS appkit-1504.76 Version 10.12.2 (Build 16C67))
of 2017-01-07"
emacs-repository-version
nil
而且发现有个gnutls的问题。而且很卡 。试了几下,滚回去继续用25.1。
(emacs-version)
"GNU Emacs 26.0.50.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911))
of 2017-01-07"
不知道多线程怎么使用,org-babel-execute-src-block
执行一段代码,在返回之前 Emacs 依然 hangs。
仔细看标題,只是在Elisp中支持多线程。
所以,要对現有package进行修改⋯⋯
大意了 。起先也在想是不是要等 pakcage 支持,粗略扫了一眼上边的信息,都是 .c 文件,也没看到 async-call
之类的函数,以为在底层实现了,创建子进程自然都异步了。
如果要等 package 支持,也许不必 26.1,在 25.1 上自行包装一下就可以了:
ztlevi
2017 年8 月 21 日 17:44
12
1 个赞
LdBeth
2017 年8 月 21 日 19:00
13
这个 Timp 和 async 本质上没区别,都是通过 fork 一个 emacs 进程实现的伪多线程/异步。劣势在于无法共享变量。
Concurrency 其实是并发,和并行(Parallel)也有区别……
能并发就代表有原生多线程支持了。