Mercurial > core / lisp/std/tests/thread.lisp
changeset 692: |
f51b73f49946 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Thu, 03 Oct 2024 17:56:11 -0400 |
permissions: |
-rw-r--r-- |
description: |
std/task and tests |
1 ;;; thread.lisp --- Thread Tests 6 (in-package :std/tests) 9 (deftest with-threads () 10 "Test with-threads macro." 11 (with-threads (4 :args (&optional (a 0) (b 1) (c 2))) 12 (is (= 3 (+ a b c))))) 15 "Test standard thread functionality." 16 (is (eq *current-thread* 17 (find (thread-name *current-thread*) (list-all-threads) 18 :key #'thread-name :test #'equal))) 19 (is (find-thread-by-id (car (thread-id-list)))) 20 (is (not (zerop (thread-count)))) 22 (make-threads 4 (lambda () (is (= 42 (1+ 41)))) :name "threads"))) 23 (loop for th in threads 24 do (sb-thread:join-thread th)) 25 (loop for th in threads 26 collect (is (not (sb-thread:thread-alive-p th))))) 27 (let ((m (make-mutex :name "mutex-test"))) 32 (make-thread (lambda () 33 (with-mutex (m :timeout 0.1) 36 (make-thread (lambda () 37 (with-mutex (m :timeout 0.1) 40 (s (make-semaphore :name "semaphore-test")) 41 (th (make-thread (lambda () (wait-on-semaphore s))))) 42 (is (equal (multiple-value-list (join-thread th :timeout .001 :default sym)) 45 (is (join-thread th))) 46 (signals join-thread-error (join-thread *current-thread*)) 48 (let ((m (make-mutex :name "rlock-test"))) 49 (is (not (with-mutex (m) (join-thread (make-thread (lambda () (with-recursive-lock (m :wait-p nil) t))))))) 50 (join-thread (make-thread (lambda () (with-recursive-lock (m :wait-p nil) t)))))) 51 (let ((queue (make-waitqueue :name "queue-test")) 52 (lock (make-mutex :name "lock-test")) 55 (labels ((in-new-thread () 57 (assert (eql (mutex-owner lock) *current-thread*)) 58 (condition-wait queue lock) 59 (assert (eql (mutex-owner lock) *current-thread*)) 62 (setf th (make-thread #'in-new-thread)) 64 (is (null (mutex-owner lock))) 67 (condition-notify queue)) 68 (is (= 0 (join-thread th)))))) 71 "Test various timer functionality." 72 (sb-int:with-progressive-timeout (ttl :seconds 2)