in reply to Tk and Threads (again)

I suspect you'll need to use a form of apartment threading (I call it zone threading) where multiple objects run in their own thread (in this case, Tk::MainWindow and all its descendents).

To expose the $mw object to the child threads, you'll need to create a proxy object (possibly as a threads::shared object) to wrap the Thread::Queue::Any back to the Tk "zone". You'll probably need to use AUTOLOAD within the proxy, as enumerating the entire set of calls possible on $mw is pretty difficult.

I'll offer Thread::Apartment::Client as an implementation of the concept.

However, Tk presents an add'l sticky issue: its a heavy user of closures, and passing closures between threads is not possible (and the closure should probably always run in its originating thread anyway). I hope to provide a solution to this in Thread::Apartment via proxied closures.

Replies are listed 'Best First'.
Re^2: Tk and Threads (again)
by Ace128 (Hermit) on Jan 22, 2006 at 18:30 UTC
    Is this for having a second MainLoop? (another seperate Tk thingy) If so, nice! Since the only thing they share is the one scalar from $thread_queue (which is just the path to where the file is). Rest is created in the thread and shown. No need to return anything if the thread can do it all!
      Is this for having a second MainLoop?

      No, its just a means to simplify the interaction between threads; you shouldn't need a 2nd MainLoop, just a $mw->repeat() call within the Tk thread that goes off to test the Thread::Queue every 100 msecs or so. The rest of the threads use the client proxy as a surrogate for making calls directly on $mw. (Of course, there's the little matter of marshalling params to the Tk thread, and getting results back...again, see Thread::Apartment for its marshal/unmarshal methods.)

      Hopefully, I'll find time in the next couple of months to finalize Thread::Apartment support for closures, plus a few other things, and then implement a Tk::Threaded that will make all of this much simpler.

        Now, that would be lovely to implement for you all actually! :)