aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/thread-tests.el
diff options
context:
space:
mode:
authorMichael Albinus2018-07-22 11:53:24 +0200
committerMichael Albinus2018-07-22 11:53:24 +0200
commite23727978dbb07d68f730ffa60b22d59d065850e (patch)
tree7ed37a1f0078ba6032a7d924f218c764330a98c8 /test/src/thread-tests.el
parentb7ca3d5d932bad6900296679ab87f7d0d64d1de9 (diff)
downloademacs-e23727978dbb07d68f730ffa60b22d59d065850e.tar.gz
emacs-e23727978dbb07d68f730ffa60b22d59d065850e.zip
thread-join returns the result of finished thread
* doc/lispref/threads.texi (Basic Thread Functions): * etc/NEWS: Document return value of `thread-join'. * src/thread.c (invoke_thread_function, Fmake_thread) (init_main_thread): Set result. (Fthread_join): Propagate signals, and return result. (Vmain_thread): New defvar. * src/thread.h (struct thread_state): Add `result' field. * test/src/thread-tests.el (threads-join): Test also return value. (threads-join-error): New test. (threads-mutex-signal): Check for propagation of `quit' signal.
Diffstat (limited to 'test/src/thread-tests.el')
-rw-r--r--test/src/thread-tests.el23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el
index a447fb3914e..364f6d61f05 100644
--- a/test/src/thread-tests.el
+++ b/test/src/thread-tests.el
@@ -100,15 +100,24 @@
100 (progn 100 (progn
101 (setq threads-test-global nil) 101 (setq threads-test-global nil)
102 (let ((thread (make-thread #'threads-test-thread1))) 102 (let ((thread (make-thread #'threads-test-thread1)))
103 (thread-join thread) 103 (and (= (thread-join thread) 23)
104 (and threads-test-global 104 (= threads-test-global 23)
105 (not (thread-alive-p thread))))))) 105 (not (thread-alive-p thread)))))))
106 106
107(ert-deftest threads-join-self () 107(ert-deftest threads-join-self ()
108 "Cannot `thread-join' the current thread." 108 "Cannot `thread-join' the current thread."
109 (skip-unless (featurep 'threads)) 109 (skip-unless (featurep 'threads))
110 (should-error (thread-join (current-thread)))) 110 (should-error (thread-join (current-thread))))
111 111
112(ert-deftest threads-join-error ()
113 "Test of error signalling from `thread-join'."
114 :tags '(:unstable)
115 (skip-unless (featurep 'threads))
116 (let ((thread (make-thread #'threads-call-error)))
117 (while (thread-alive-p thread)
118 (thread-yield))
119 (should-error (thread-join thread))))
120
112(defvar threads-test-binding nil) 121(defvar threads-test-binding nil)
113 122
114(defun threads-test-thread2 () 123(defun threads-test-thread2 ()
@@ -197,7 +206,7 @@
197(ert-deftest threads-mutex-signal () 206(ert-deftest threads-mutex-signal ()
198 "Test signaling a blocked thread." 207 "Test signaling a blocked thread."
199 (skip-unless (featurep 'threads)) 208 (skip-unless (featurep 'threads))
200 (should 209 (should-error
201 (progn 210 (progn
202 (setq threads-mutex (make-mutex)) 211 (setq threads-mutex (make-mutex))
203 (setq threads-mutex-key nil) 212 (setq threads-mutex-key nil)
@@ -206,8 +215,10 @@
206 (while (not threads-mutex-key) 215 (while (not threads-mutex-key)
207 (thread-yield)) 216 (thread-yield))
208 (thread-signal thr 'quit nil) 217 (thread-signal thr 'quit nil)
209 (thread-join thr)) 218 ;; `quit' is not catched by `should-error'. We must indicate it.
210 t))) 219 (condition-case nil
220 (thread-join thr)
221 (quit (signal 'error nil)))))))
211 222
212(defun threads-test-io-switch () 223(defun threads-test-io-switch ()
213 (setq threads-test-global 23)) 224 (setq threads-test-global 23))