Skip to content

Commit 6871577

Browse files
committed
Add semaphore test
1 parent b082405 commit 6871577

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

aio-test.el

+22
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,25 @@ aio-timeout to cause the test to fail."
113113
(nth 1 (aio-chain (cdr filter)))))
114114
(should (equal "1 2 3\n"
115115
(nth 1 (aio-chain (cdr filter))))))))
116+
117+
(ert-deftest sem ()
118+
(aio-with-test 5
119+
(let ((n 64)
120+
(sem (aio-sem 0))
121+
(promises ())
122+
(output ()))
123+
(dotimes (i n)
124+
;; Queue up threads on the semaphore
125+
(push
126+
(aio-with-async
127+
(aio-await (aio-sem-wait sem))
128+
(push i output))
129+
promises))
130+
;; Allow threads to run
131+
(dotimes (_ n)
132+
(aio-sem-post sem))
133+
;; Wait for all threads to complete (join)
134+
(aio-await (aio-all promises))
135+
;; Check that the threads ran in correct order
136+
(should (equal (number-sequence 0 63)
137+
(nreverse output))))))

0 commit comments

Comments
 (0)