On 18 April 2012 10:56, Stelian Ionescu sionescu@cddr.org wrote:
Then I'd be grateful if you could add timeout support and send us a patch :)
Ok -- so I guess I need to write a patch that covers as many Lisps as I can get my hands on for testing, and a test that demonstrates that it works correctly.
Before I go ahead and do that, below is an example showing what the ABCL proposed implementation would look like, for feedback. Some questions and notes:
1. I'm using an &optional argument which seems the tidiest to me. Would anyone prefer to have a separate function instead, say CONDITION-TIMED-WAIT, or a &key?
2. The ABCL implementation cannot tell you whether the wait returned because of timeout (although others can), so to help people write portable code the return value would have to remain undefined.
3. For those implementations which can't support it yet, it might be an option to simply not accept the &optional argument, so that programs that need it fail to compile rather than failing at runtime on implementations that lack it. Alternatively I could make those implementation raise an error if TIMEOUT is not NIL. I guess timeout support could be advertised in *FEATURES*.
Thanks, Thomas
diff --git a/src/impl-abcl.lisp b/src/impl-abcl.lisp index 3c08db4..5b79271 100644 --- a/src/impl-abcl.lisp +++ b/src/impl-abcl.lisp @@ -98,10 +98,12 @@ Distributed under the MIT license (see LICENSE file) (defstruct condition-variable (name "Anonymous condition variable"))
-(defun condition-wait (condition lock) +(defun condition-wait (condition lock &optional timeout) (threads:synchronized-on condition (release-lock lock) - (threads:object-wait condition)) + (if timeout + (threads:object-wait condition timeout) + (threads:object-wait condition))) (acquire-lock lock))
(defun condition-notify (condition)