emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 9c4d2af: Minor improvements in the new condvar test


From: Eli Zaretskii
Subject: [Emacs-diffs] master 9c4d2af: Minor improvements in the new condvar test
Date: Fri, 13 Jan 2017 14:14:17 +0000 (UTC)

branch: master
commit 9c4d2afaa5786107aa79728b4703296b9289bf0b
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Minor improvements in the new condvar test
    
    * test/src/thread-tests.el (threads-test-condvar-wait): Use
    with-mutex instead of emulating it inline.
    (threads-condvar-wait): Improve comments.  Check that the new
    thread is alive before waiting for it to become blocked on the
    conditional variable.
---
 test/src/thread-tests.el |   25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el
index 71b2018..61809e1 100644
--- a/test/src/thread-tests.el
+++ b/test/src/thread-tests.el
@@ -245,34 +245,37 @@
     (should-not (thread-alive-p thread))))
 
 (defvar threads-condvar nil)
+
 (defun threads-test-condvar-wait ()
-  ;; Wait for condvar to be notified
-  (mutex-lock (condition-mutex threads-condvar))
-  (condition-wait threads-condvar)
-  (mutex-unlock (condition-mutex threads-condvar))
+  ;; Wait for condvar to be notified.
+  (with-mutex (condition-mutex threads-condvar)
+    (condition-wait threads-condvar))
   ;; Wait again, it will be signaled.
   (with-mutex (condition-mutex threads-condvar)
     (condition-wait threads-condvar)))
 
 (ert-deftest threads-condvar-wait ()
   "test waiting on conditional variable"
-  (let* ((cv-mutex (make-mutex))
-         (nthreads (length (all-threads)))
-         new-thread)
+  (let ((cv-mutex (make-mutex))
+        (nthreads (length (all-threads)))
+        new-thread)
     (setq threads-condvar (make-condition-variable cv-mutex))
     (setq new-thread (make-thread #'threads-test-condvar-wait))
-    (while (not (eq (thread--blocker new-thread) threads-condvar))
-      (thread-yield))
+
+    ;; Make sure new-thread is alive.
     (should (thread-alive-p new-thread))
     (should (= (length (all-threads)) (1+ nthreads)))
+    ;; Wait for new-thread to become blocked on the condvar.
+    (while (not (eq (thread--blocker new-thread) threads-condvar))
+      (thread-yield))
+
     ;; Notify the waiting thread.
     (with-mutex cv-mutex
       (condition-notify threads-condvar t))
-
     ;; Allow new-thread to process the notification.
     (sleep-for 0.1)
     ;; Make sure the thread is still there.  This used to fail due to
-    ;; a bug in condition_wait_callback.
+    ;; a bug in thread.c:condition_wait_callback.
     (should (thread-alive-p new-thread))
     (should (= (length (all-threads)) (1+ nthreads)))
     (should (memq new-thread (all-threads)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]