diff --git a/apiv2/api-condition-variables.lisp b/apiv2/api-condition-variables.lisp index 5f2adf0..51f5d25 100644 --- a/apiv2/api-condition-variables.lisp +++ b/apiv2/api-condition-variables.lisp @@ -83,9 +83,9 @@ It is unspecified which thread gets a wakeup and does not necessarily relate to the order that the threads went to sleep in. - CONDITION-NOTIFY returns T if a thread was woken up, otherwise NIL." + CONDITION-NOTIFY returns always NIL." (%condition-notify condition-variable) - t) + nil) (defun condition-broadcast (condition-variable) "Notify all threads waiting for CONDITION-VARIABLE. @@ -93,7 +93,6 @@ The order of wakeup is unspecified and does not necessarily relate to the order that the threads went to sleep in. - CONDITION-BROADCAST returns T if at least one thread was woken up, - otherwise NIL." + CONDITION-BROADCAST returns always NIL." (%condition-broadcast condition-variable) - t) + nil) diff --git a/docs/content/condition-variables/condition-broadcast.md b/docs/content/condition-variables/condition-broadcast.md index 005b4b9..1b22ed5 100644 --- a/docs/content/condition-variables/condition-broadcast.md +++ b/docs/content/condition-variables/condition-broadcast.md @@ -19,9 +19,7 @@ boolean](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_g.htm#gene Notify all the threads waiting for `condition-variable`. -Returns -[true](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_t.htm#true) -if at least one thread was woken up, otherwise +Returns always [false](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#false). #### Exceptional situations: @@ -40,3 +38,8 @@ if `condition-variable` is not a The order of wakeup is unspecified and does not necessarily relate to the order in which the threads went to sleep. + +**condition-broadcast** always returns +[false](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#false) +because not all implementations' primitives can tell whether or not +some threads were indeed woken up. diff --git a/docs/content/condition-variables/condition-notify.md b/docs/content/condition-variables/condition-notify.md index 6853952..4ad565f 100644 --- a/docs/content/condition-variables/condition-notify.md +++ b/docs/content/condition-variables/condition-notify.md @@ -19,9 +19,7 @@ boolean](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_g.htm#gene Notify one of the threads waiting for `condition-variable`. -Returns -[true](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_t.htm#true) -if a thread was woken up, otherwise +Returns always [false](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#false). #### Exceptional situations: @@ -40,3 +38,8 @@ if `condition-variable` is not a It is unspecified which thread gets a wakeup and does not necessarily relate to the order in which the threads went to sleep. + +**condition-notify** always returns +[false](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#false) +because not all implementations' primitives can tell whether or not +some threads were indeed woken up. diff --git a/test/tests-v2.lisp b/test/tests-v2.lisp index 0adb647..72d8588 100644 --- a/test/tests-v2.lisp +++ b/test/tests-v2.lisp @@ -430,6 +430,35 @@ lock." (with-lock-held (res-lock) (condition-wait res-cv res-lock) (is-false lock-was-acquired-p))))))) + +#+#.(bt2::implemented-p* 'bt2:make-condition-variable) +(test condition-notify.no-waiting-threads + "Test that `CONDITION-NOTIFY` returns NIL whether or not there are +threads waiting." + (let ((lock (make-lock :name "Test lock")) + (cv (make-condition-variable :name "Test condition variable"))) + (is-false (condition-notify cv)) + (make-thread (lambda () + (with-lock-held (lock) + (condition-wait cv lock)))) + (is-false (condition-notify cv)))) + +#+#.(bt2::implemented-p* 'bt2:make-condition-variable) +(test condition-broadcast.return-value + "Test that `CONDITION-BROADCAST` returns NIL whether or not there +are threads waiting." + (let ((lock (make-lock :name "Test lock")) + (cv (make-condition-variable :name "Test condition variable"))) + (is-false (condition-notify cv)) + (make-thread (lambda () + (with-lock-held (lock) + (condition-wait cv lock))) + :name "Waiting thread 1") + (make-thread (lambda () + (with-lock-held (lock) + (condition-wait cv lock))) + :name "Waiting thread 2") + (is-false (condition-broadcast cv)))) ;;;