From martin at lispworks.com Wed Dec 1 12:08:07 2010 From: martin at lispworks.com (Martin Simmons) Date: Wed, 1 Dec 2010 12:08:07 GMT Subject: [Bordeaux-threads-devel] Clarifying some behavior in the documentation In-Reply-To: (message from Vladimir Sedach on Tue, 30 Nov 2010 13:27:13 -0500) References: <201011301227.oAUCRSbh004629@higson.cam.lispworks.com> Message-ID: <201012011208.oB1C876S028746@higson.cam.lispworks.com> >>>>> On Tue, 30 Nov 2010 13:27:13 -0500, Vladimir Sedach said: > > >> 1. At least one implementation (SBCL) requires that the lock on which > >> condition-wait is called is to be held by the thread that calls > >> condition-notify on the corresponding CV. This should be mentioned in > >> the documentation as a requirement. > > > > Yes, this is a standard, but ill-documented, requirement for condition > > variables. ?The lock is needed to synchronize the notify with the change to > > the underlying data in the application. > > At least on Clozure, B-T implements condition-wait/notify with > semaphores, so this appears to work fine, even though on other > implementations it might lead to race conditions. OK, I see what you mean -- the implementation of condition-notify might not be thread safe within itself unless the lock is held. I was referring to a different problem though. If you call condition-notify without holding the lock, then you can lose notifications, i.e. condition-wait might never wake up. A typical use of condition-wait is like this: (defun wait-for-it () (with-lock-held (lock) (loop (when (application-state-says-ready-p) (return)) ;; ** (condition-wait cv lock)))) and the corresponding use of condition-notify should be like this: (defun provide-it () (with-lock-held (lock) (setf (application-state-says-ready-p) t) (condition-notify cv))) You must use with-lock-held to change the application state and notify atomically w.r.t. the call to application-state-says-ready-p and condition-wait. This is because, at least according to the pthreads definition, condition variables have no memory of calls to notify that occurred when noone was waiting. If provide-it can run (in another thread) at the point labelled ** in wait-for-it, then the notify will be lost. The lock prevents provide-it from doing that. -- Martin Simmons LispWorks Ltd http://www.lispworks.com/ From evenson at panix.com Fri Dec 3 13:37:52 2010 From: evenson at panix.com (Mark Evenson) Date: Fri, 03 Dec 2010 14:37:52 +0100 Subject: [Bordeaux-threads-devel] Patch for ABCL against BORDEAUX-THREADS-0.8.0 Message-ID: ABCL's multithreading symbols have moved to THREADS package (this was deprecated with abcl-0.18 and removed with abcl-0.22). Implement CONDITION-WAIT and CONDITION-NOTIFY for ABCL. Use 10ms pause for ABCL's THREAD-YIELD. -- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now." -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: bordeaux-threads-abcl.patch URL: From martin at lispworks.com Fri Dec 3 15:56:32 2010 From: martin at lispworks.com (Martin Simmons) Date: Fri, 3 Dec 2010 15:56:32 GMT Subject: [Bordeaux-threads-devel] Patch for ABCL against BORDEAUX-THREADS-0.8.0 In-Reply-To: (message from Mark Evenson on Fri, 03 Dec 2010 14:37:52 +0100) References: Message-ID: <201012031556.oB3FuWEt000414@higson.cam.lispworks.com> >>>>> On Fri, 03 Dec 2010 14:37:52 +0100, Mark Evenson said: > > Implement CONDITION-WAIT and CONDITION-NOTIFY for ABCL. That version of CONDITION-WAIT won't work properly: - More than one thread can wake up from a single call to CONDITION-NOTIFY. - If CONDITION-WAIT is called while another thread is inside THREAD-YIELD, then any pending "active" state will be lost (i.e. CONDITION-NOTIFY will fail to wake a thread). Also, what is te purpose of the CONDITION-VARIABLE-LOCK (which is only used by CONDITION-NOTIFY)? __Martin From evenson at panix.com Sat Dec 4 20:38:52 2010 From: evenson at panix.com (Mark Evenson) Date: Sat, 04 Dec 2010 21:38:52 +0100 Subject: [Bordeaux-threads-devel] Patch for ABCL against BORDEAUX-THREADS-0.8.0 In-Reply-To: <201012031556.oB3FuWEt000414@higson.cam.lispworks.com> References: <201012031556.oB3FuWEt000414@higson.cam.lispworks.com> Message-ID: <4CFAA6DC.5030006@panix.com> On 12/3/10 4:56 PM, Martin Simmons wrote: >>>>>> On Fri, 03 Dec 2010 14:37:52 +0100, Mark Evenson said: >> >> Implement CONDITION-WAIT and CONDITION-NOTIFY for ABCL. > > That version of CONDITION-WAIT won't work properly: Indeed it won't: thanks for the comments, and the kick in the butt. After studying the needed abstractions in more detail I've [reimplemented most of the BORDEAUX-THREADS interfaces for ABCL based on the java.util.concurrent.ReentrantLock][1]. This code should now correctly implement the POSIX-style condition variables, the recursively held locks, and the form of lock acquisition that returns immediately. Please consider the referenced patch for inclusion in BORDEAUX-THREADS. [1]: http://slack.net/~evenson/abcl/hunchentoot/bordeaux-threads-abcl-20101204a.diff -- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now." From lisp.linux at gmail.com Sat Dec 11 09:47:15 2010 From: lisp.linux at gmail.com (Antony) Date: Sat, 11 Dec 2010 01:47:15 -0800 Subject: [Bordeaux-threads-devel] binding output stream in thread for slime use Message-ID: <4D0348A3.2000105@gmail.com> Hi I am trying to use bordeaux threads. Trying to figure out how to make output from a thread function appear in slime instead of the lisp terminal. The lisp I am using is Clozure Common Lisp Version 1.6-r14468M (WindowsX8664) I beleive I have the latest bordeaux threads Following is my test code. I hope the intentions are clear. What am I doing wrong or missing? Code follows Thanks, -Antony (asdf:oos 'asdf:load-op :bordeaux-threads) (format t "~%appearing in slime") (defun thread-test () (format t "~%appearing in lisp terminal: ~A" (bordeaux-threads:thread-name (bordeaux-threads:current-thread)))) (let ((bindings '((*standard-input* . *standard-input*) (*standard-output* . *standard-output*) (*query-io* . *query-io*) (*trace-output* . *trace-output*)))) ;;is this correct? (dolist (name '("foo" "bar")) (bordeaux-threads:make-thread #'thread-test :name name :initial-bindings bindings))) From fahree at gmail.com Tue Dec 14 01:22:11 2010 From: fahree at gmail.com (=?ISO-8859-1?Q?Far=E9?=) Date: Mon, 13 Dec 2010 20:22:11 -0500 Subject: [Bordeaux-threads-devel] patch for thread-wait Message-ID: Dear bordeaux-threads developers, I have a patch that adds bt support for thread-wait and thread-wait-with-timeout, modelled after the process-wait and process-wait-with-timeout functions sported by several Lisp APIs. This API should be considered a legacy compatibility API, as these operations may have made sense long ago on timesharing monoprocessors, but are necessarily expensive on multiprocessors. Nevertheless, we had a use for them at ITA, and I threw together this compatibility support, until we get our code cleaned up. Please consider this patch for inclusion, though it has only been lightly tested. PS: I also have a patch to add XCVB support to bordeaux-threads, though you might not be interested. [ Fran?ois-Ren? ?VB Rideau | Reflection&Cybernethics | http://fare.tunes.org ] As the Chinese say, 1001 words is worth more than a picture. ? John McCarthy -------------- next part -------------- A non-text attachment was scrubbed... Name: bt.diff Type: text/x-patch Size: 6640 bytes Desc: not available URL: From vsedach at gmail.com Wed Dec 15 02:35:52 2010 From: vsedach at gmail.com (Vladimir Sedach) Date: Tue, 14 Dec 2010 21:35:52 -0500 Subject: [Bordeaux-threads-devel] binding output stream in thread for slime use In-Reply-To: <4D0348A3.2000105@gmail.com> References: <4D0348A3.2000105@gmail.com> Message-ID: The way I capture the slime output stream is this: (let ((s *standard-output*)) (defun foo () (format s "Debug output"))) And evaluate it with M-x or by pasting into the REPL itself. That's guaranteed to make foo capture a binding to the slime output stream. To get your approach to work you need to do: (let ((bindings (list (cons '*standard-output* *standard-output*)))) (bt:make-thread #'foo :initial-bindings bindings)) That is, the value of *standard-output* needs to be evaluated. Hope that helps. Vladimir 2010/12/11 Antony : > Hi > > I am trying to use bordeaux threads. > Trying to figure out how to make output from a thread function appear in > slime instead of the lisp terminal. > The lisp I am using is > Clozure Common Lisp Version 1.6-r14468M ?(WindowsX8664) > > I beleive I have the latest bordeaux threads > > Following is my test code. I hope the intentions are clear. > > What am I doing wrong or missing? > > Code follows > Thanks, > -Antony > > (asdf:oos 'asdf:load-op :bordeaux-threads) > > (format t "~%appearing in slime") > > (defun thread-test () > ? (format t "~%appearing in lisp terminal: ~A" > ? ? ? ? ? (bordeaux-threads:thread-name > (bordeaux-threads:current-thread)))) > > (let ((bindings > ? ? ? ?'((*standard-input* . *standard-input*) > ? ? ? ? ?(*standard-output* . *standard-output*) > ? ? ? ? ?(*query-io* . *query-io*) > ? ? ? ? ?(*trace-output* . *trace-output*)))) ?;;is this correct? > ? (dolist (name '("foo" "bar")) > ? ? ? ? (bordeaux-threads:make-thread #'thread-test > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :name name > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :initial-bindings bindings))) > > > _______________________________________________ > Bordeaux-threads-devel mailing list > Bordeaux-threads-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/bordeaux-threads-devel > From lisp.linux at gmail.com Sun Dec 19 18:11:06 2010 From: lisp.linux at gmail.com (Antony) Date: Sun, 19 Dec 2010 10:11:06 -0800 Subject: [Bordeaux-threads-devel] binding output stream in thread for slime use In-Reply-To: References: <4D0348A3.2000105@gmail.com> Message-ID: <4D0E4ABA.5040601@gmail.com> Thank you very much. It's clear now and works too. -Antony On 12/14/2010 6:35 PM, Vladimir Sedach wrote: > To get your approach to work you need to do: > > (let ((bindings (list (cons '*standard-output* *standard-output*)))) > (bt:make-thread #'foo :initial-bindings bindings)) > > That is, the value of *standard-output* needs to be evaluated. > From tcr at freebits.de Thu Dec 30 12:48:10 2010 From: tcr at freebits.de (Tobias C Rittweiler) Date: Thu, 30 Dec 2010 12:48:10 +0000 Subject: [Bordeaux-threads-devel] binding output stream in thread for slime use References: <4D0348A3.2000105@gmail.com> Message-ID: In article <4D0348A3.2000105 at gmail.com>, Antony wrote: > Hi > > I am trying to use bordeaux threads. > Trying to figure out how to make output from a thread function appear in > slime instead of the lisp terminal. > The lisp I am using is > Clozure Common Lisp Version 1.6-r14468M (WindowsX8664) > > I beleive I have the latest bordeaux threads > > Following is my test code. I hope the intentions are clear. > > What am I doing wrong or missing? > > Code follows > Thanks, > -Antony > > (asdf:oos 'asdf:load-op :bordeaux-threads) > > (format t "~%appearing in slime") > > (defun thread-test () > (format t "~%appearing in lisp terminal: ~A" > (bordeaux-threads:thread-name > (bordeaux-threads:current-thread)))) > > (let ((bindings > '((*standard-input* . *standard-input*) > (*standard-output* . *standard-output*) > (*query-io* . *query-io*) > (*trace-output* . *trace-output*)))) ;;is this correct? > (dolist (name '("foo" "bar")) > (bordeaux-threads:make-thread #'thread-test > :name name > :initial-bindings bindings))) You can place (setq swank:*globally-redirect-io* t) into your ~/.swank.lisp to globally install the slime repl streams, so all output will show up in your *slime-repl ...* buffer. Another way, next to what Vladimir said, is to use (define-symbol-macro *repl-stream* (swank::connection.user-output (swank::default-connection))) I'd say this question would have been more appropriate on slime-devel. :-) Anyway, hth, -T.