aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorDmitry Gutov2025-08-09 22:40:07 +0300
committerDmitry Gutov2025-08-09 22:40:07 +0300
commit07eb39f1132ceb15e80e7912445890faa8f5b78c (patch)
treee6ab9c32a334fca746e68a9ac62728e312cfcd1c /test/src
parentc4af4b39018923fdfc22b515acc1f6ba3f2b024d (diff)
downloademacs-07eb39f1132ceb15e80e7912445890faa8f5b78c.tar.gz
emacs-07eb39f1132ceb15e80e7912445890faa8f5b78c.zip
Allow thread's buffer to be killed, by default
* src/thread.c (Fmake_thread): Add new argument (bug#76969). (thread_set_error): New function, extracted from thread-signal. (Fthread_buffer_disposition): Add getter. (Fthread_set_buffer_disposition): And setter. (thread_check_current_buffer): Check the values of threads' buffer_disposition. (thread_all_before_buffer_killed): New function. (init_threads): Set buffer_disposition to nil for the main thread. (syms_of_threads): Add new symbols and define the error. * src/thread.h (thread_state): New field buffer_disposition. (thread_all_before_buffer_killed): Declare. * src/buffer.c (Fkill_buffer): Call thread_check_current_buffer one more time after all hooks and after that call thread_all_before_buffer_killed. * src/comp.c (ABI_VERSION): Increase the value. * test/src/thread-tests.el (thread-buffer-disposition-t) (thread-buffer-disposition-nil) (thread-buffer-disposition-silently) (thread-set-buffer-disposition) (thread-set-buffer-disposition-main-thread): New tests. * doc/lispref/threads.texi (Basic Thread Functions): Document buffer-disposition in make-thread and its getter and setter. * etc/NEWS: Add entry.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/thread-tests.el64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el
index 9a065187b5e..0b9e8f96c09 100644
--- a/test/src/thread-tests.el
+++ b/test/src/thread-tests.el
@@ -398,6 +398,70 @@
398 (let ((th (make-thread 'ignore))) 398 (let ((th (make-thread 'ignore)))
399 (should-not (equal th main-thread)))) 399 (should-not (equal th main-thread))))
400 400
401(ert-deftest thread-buffer-disposition-t ()
402 "Test not being able to kill a bg thread's buffer."
403 (skip-unless (featurep 'threads))
404 (let ((buf (get-buffer-create " *thread-buffer-killable-nil*"))
405 thread)
406 (with-current-buffer buf
407 (setq thread
408 (make-thread
409 (lambda ()
410 (sleep-for 0.1))
411 nil
412 t)))
413 (kill-buffer buf)
414 (should (buffer-live-p buf))
415 ;; No error:
416 (thread-join thread)))
417
418(ert-deftest thread-buffer-disposition-nil ()
419 "Test killing a bg thread's buffer."
420 (skip-unless (featurep 'threads))
421 (let ((buf (get-buffer-create " *thread-buffer-killable-t*"))
422 thread)
423 (with-current-buffer buf
424 (setq thread
425 (make-thread
426 (lambda ()
427 (sleep-for 0.1)))))
428 (kill-buffer buf)
429 (should-not (buffer-live-p buf))
430 (should-error
431 (thread-join thread)
432 :type 'thread-buffer-killed)))
433
434(ert-deftest thread-buffer-disposition-silently ()
435 "Test killing a bg thread's buffer silently."
436 (skip-unless (featurep 'threads))
437 (let ((buf (get-buffer-create " *thread-buffer-killable-t*"))
438 thread)
439 (with-current-buffer buf
440 (setq thread
441 (make-thread
442 (lambda ()
443 (sleep-for 0.1))
444 nil
445 'silently)))
446 (kill-buffer buf)
447 (should-not (buffer-live-p buf))
448 (thread-join thread)))
449
450(ert-deftest thread-set-buffer-disposition ()
451 "Test being able to modify a thread's buffer disposition."
452 (skip-unless (featurep 'threads))
453 (let ((thread (make-thread #'ignore)))
454 (should (eq (thread-buffer-disposition thread) nil))
455 (thread-set-buffer-disposition thread t)
456 (should (eq (thread-buffer-disposition thread) t))))
457
458(ert-deftest thread-set-buffer-disposition-main-thread ()
459 "Test not being able to modify main thread's buffer disposition."
460 (skip-unless (featurep 'threads))
461 (should (null (thread-buffer-disposition main-thread)))
462 (should-error (thread-set-buffer-disposition main-thread t)
463 :type 'wrong-type-argument))
464
401(defvar threads-test--var 'global) 465(defvar threads-test--var 'global)
402 466
403(ert-deftest threads-test-bug48990 () 467(ert-deftest threads-test-bug48990 ()