[ltk-user] listbox updates from separate thread

Peter Herth herth at peter-herth.de
Tue Dec 14 10:37:52 UTC 2010


Hi Kevin,

in general LTk has no support for multithreading. Mostly because threads are
supported only by a few common lisp implementations and that updating a
user-interface requires some synchronisation of some sort. Which Lisp
implementation are you using?
In the presence of multi-threading, I would strongly suggest to only communicate
with Tk from one thread only. So my solution would be to have a lisp
variable which
contains the content to be displayed in the list box, which can be
updated from any
number of threads (of course those would have to work together of some
sort not to
have random content in that variable, but thats outside of LTk) and have the LTk
thread update the list box from that variable. But as the LTk thread
is waiting for
Tk events, how to wake it up? The solution here is to have Tk create
periodic events
which are used for updates. Something like:

(defparamter *mylist* (list 1 2 3 4)) ;; this lists content is to be
continously updated

(defun update (listbox)
   (unless *shutdown-gui*
     (listbox-clear listbox)
     (listbox-append listbox *mylist*)
     (after 1000 (lambda ()
                        (update listbox)))))

The after function gets passed a time in milliseconds and a function
to call after
the time has passed. You start the update process by calling update
once, passing
it the listbox to update (you might want to add some code to update only if the
list has actually changed for efficiency...). This feature is quite
nice for any kind
of animations and very useful for background processing in LTk
applications on Lisp
implementations which are not multithreaded.

Peter




More information about the ltk-user mailing list