diff options
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/thread-tests.el | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el index 71b20185d76..61809e1681b 100644 --- a/test/src/thread-tests.el +++ b/test/src/thread-tests.el | |||
| @@ -245,34 +245,37 @@ | |||
| 245 | (should-not (thread-alive-p thread)))) | 245 | (should-not (thread-alive-p thread)))) |
| 246 | 246 | ||
| 247 | (defvar threads-condvar nil) | 247 | (defvar threads-condvar nil) |
| 248 | |||
| 248 | (defun threads-test-condvar-wait () | 249 | (defun threads-test-condvar-wait () |
| 249 | ;; Wait for condvar to be notified | 250 | ;; Wait for condvar to be notified. |
| 250 | (mutex-lock (condition-mutex threads-condvar)) | 251 | (with-mutex (condition-mutex threads-condvar) |
| 251 | (condition-wait threads-condvar) | 252 | (condition-wait threads-condvar)) |
| 252 | (mutex-unlock (condition-mutex threads-condvar)) | ||
| 253 | ;; Wait again, it will be signaled. | 253 | ;; Wait again, it will be signaled. |
| 254 | (with-mutex (condition-mutex threads-condvar) | 254 | (with-mutex (condition-mutex threads-condvar) |
| 255 | (condition-wait threads-condvar))) | 255 | (condition-wait threads-condvar))) |
| 256 | 256 | ||
| 257 | (ert-deftest threads-condvar-wait () | 257 | (ert-deftest threads-condvar-wait () |
| 258 | "test waiting on conditional variable" | 258 | "test waiting on conditional variable" |
| 259 | (let* ((cv-mutex (make-mutex)) | 259 | (let ((cv-mutex (make-mutex)) |
| 260 | (nthreads (length (all-threads))) | 260 | (nthreads (length (all-threads))) |
| 261 | new-thread) | 261 | new-thread) |
| 262 | (setq threads-condvar (make-condition-variable cv-mutex)) | 262 | (setq threads-condvar (make-condition-variable cv-mutex)) |
| 263 | (setq new-thread (make-thread #'threads-test-condvar-wait)) | 263 | (setq new-thread (make-thread #'threads-test-condvar-wait)) |
| 264 | (while (not (eq (thread--blocker new-thread) threads-condvar)) | 264 | |
| 265 | (thread-yield)) | 265 | ;; Make sure new-thread is alive. |
| 266 | (should (thread-alive-p new-thread)) | 266 | (should (thread-alive-p new-thread)) |
| 267 | (should (= (length (all-threads)) (1+ nthreads))) | 267 | (should (= (length (all-threads)) (1+ nthreads))) |
| 268 | ;; Wait for new-thread to become blocked on the condvar. | ||
| 269 | (while (not (eq (thread--blocker new-thread) threads-condvar)) | ||
| 270 | (thread-yield)) | ||
| 271 | |||
| 268 | ;; Notify the waiting thread. | 272 | ;; Notify the waiting thread. |
| 269 | (with-mutex cv-mutex | 273 | (with-mutex cv-mutex |
| 270 | (condition-notify threads-condvar t)) | 274 | (condition-notify threads-condvar t)) |
| 271 | |||
| 272 | ;; Allow new-thread to process the notification. | 275 | ;; Allow new-thread to process the notification. |
| 273 | (sleep-for 0.1) | 276 | (sleep-for 0.1) |
| 274 | ;; Make sure the thread is still there. This used to fail due to | 277 | ;; Make sure the thread is still there. This used to fail due to |
| 275 | ;; a bug in condition_wait_callback. | 278 | ;; a bug in thread.c:condition_wait_callback. |
| 276 | (should (thread-alive-p new-thread)) | 279 | (should (thread-alive-p new-thread)) |
| 277 | (should (= (length (all-threads)) (1+ nthreads))) | 280 | (should (= (length (all-threads)) (1+ nthreads))) |
| 278 | (should (memq new-thread (all-threads))) | 281 | (should (memq new-thread (all-threads))) |