Hi
Are there any plans to support a timeout for bordeaux-threads:condition-wait? The implementations I'm aware of support this threading primitive:
* ABCL could presumably do it since Java Object.wait can take a timeout * SBCL supports it using sb-thread:condition-wait with keyword :timeout [1] * anything with POSIX threads underneath could use pthread_cond_timedwait
The main variation seems to be between those implementations that use an absolute time and those that use a relative time (how long to wait in milliseconds for example).
Since I think I need this feature I might try to write a patch to do this for ABCL and SBCL if there is nothing already in the works (unless there is some technical problem I'm not seeing?)
Thanks Thomas Munro
On Wed, 2012-04-04 at 22:33 +0100, Thomas Munro wrote:
Hi
Are there any plans to support a timeout for bordeaux-threads:condition-wait? The implementations I'm aware of support this threading primitive:
- ABCL could presumably do it since Java Object.wait can take a timeout
- SBCL supports it using sb-thread:condition-wait with keyword :timeout [1]
- anything with POSIX threads underneath could use pthread_cond_timedwait
The main variation seems to be between those implementations that use an absolute time and those that use a relative time (how long to wait in milliseconds for example).
Since I think I need this feature I might try to write a patch to do this for ABCL and SBCL if there is nothing already in the works (unless there is some technical problem I'm not seeing?)
I'd like to, but what do we do for those implementations that don't support timeouts ?
On 17 April 2012 15:11, Stelian Ionescu sionescu@cddr.org wrote:
I'd like to, but what do we do for those implementations that don't support timeouts ?
I went through the existing implementations and googled for timeout variants of the mechanisms being used and found these:
ABCL: (threads:object-wait condition timeout) Allegro: ? Clisp: (mt:exemption exemption mutex :timeout timeout) Clozure: (ccl:timed-wait-on-semaphore semaphore timeout) CMUCL: ? Corman: ? ECL: (mp:condition-variable-timedwait condition mutex timeout) LispWorks simulated: ? LispWorks 6: (mp:condition-variable-wait condition mutex :timeout timeout) MCL: ? SBCL: (sb-thread:condition-wait condition mutex :timeout timeout) SCL: (thread:cond-var-timedwait condition mutex timeout)
I couldn't immediately grok those with question marks, but I suspect it's possible for most of them though. I hope someone who knows those systems can comment.
I don't have any suggestion on what to do if there is no implementation apart from the obvious and unsatisfactory 'raise an error at runtime'.
On Wed, 2012-04-18 at 01:20 +0100, Thomas Munro wrote:
On 17 April 2012 15:11, Stelian Ionescu sionescu@cddr.org wrote:
I'd like to, but what do we do for those implementations that don't support timeouts ?
I went through the existing implementations and googled for timeout variants of the mechanisms being used and found these:
ABCL: (threads:object-wait condition timeout) Allegro: ? Clisp: (mt:exemption exemption mutex :timeout timeout) Clozure: (ccl:timed-wait-on-semaphore semaphore timeout) CMUCL: ? Corman: ? ECL: (mp:condition-variable-timedwait condition mutex timeout) LispWorks simulated: ? LispWorks 6: (mp:condition-variable-wait condition mutex :timeout timeout) MCL: ? SBCL: (sb-thread:condition-wait condition mutex :timeout timeout) SCL: (thread:cond-var-timedwait condition mutex timeout)
I couldn't immediately grok those with question marks, but I suspect it's possible for most of them though. I hope someone who knows those systems can comment.
I don't have any suggestion on what to do if there is no implementation apart from the obvious and unsatisfactory 'raise an error at runtime'.
Then I'd be grateful if you could add timeout support and send us a patch :)
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)
I have added a :timeout option to condition-wait.
git pull https://github.com/lmj/bordeaux-threads
Tested on ABCL, Allegro, CLISP, Clozure, ECL, LispWorks 6.1, and SBCL.
I don't have SCL, but if the documentation is correct then it should be OK.
On Tue, Apr 17, 2012 at 8:20 PM, Thomas Munro munro@ip9.org wrote:
On 17 April 2012 15:11, Stelian Ionescu sionescu@cddr.org wrote:
I'd like to, but what do we do for those implementations that don't support timeouts ?
I went through the existing implementations and googled for timeout variants of the mechanisms being used and found these:
ABCL: (threads:object-wait condition timeout) Allegro: ? Clisp: (mt:exemption exemption mutex :timeout timeout) Clozure: (ccl:timed-wait-on-semaphore semaphore timeout) CMUCL: ? Corman: ? ECL: (mp:condition-variable-timedwait condition mutex timeout) LispWorks simulated: ? LispWorks 6: (mp:condition-variable-wait condition mutex :timeout timeout) MCL: ? SBCL: (sb-thread:condition-wait condition mutex :timeout timeout) SCL: (thread:cond-var-timedwait condition mutex timeout)
I couldn't immediately grok those with question marks, but I suspect it's possible for most of them though. I hope someone who knows those systems can comment.
I don't have any suggestion on what to do if there is no implementation apart from the obvious and unsatisfactory 'raise an error at runtime'.
Bordeaux-threads-devel mailing list Bordeaux-threads-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/bordeaux-threads-devel
On Sat, 2013-09-14 at 12:07 -0400, James M. Lawrence wrote:
I have added a :timeout option to condition-wait.
git pull https://github.com/lmj/bordeaux-threads
Tested on ABCL, Allegro, CLISP, Clozure, ECL, LispWorks 6.1, and SBCL.
I don't have SCL, but if the documentation is correct then it should be OK.
Please make a pull request.
bordeaux-threads-devel@common-lisp.net