in reply to Share symbol table between threads

Using the standard threads distributed with Perl 5.8.x:

  1. If you use the module in your main thread before spawning threads A & B, threads A & B will be able to use the module.
  2. Or, if you require the module in thread A and then spawn thread B from within thread A, the module will be available to thread B.
  3. If you spawn thread A from the main thread, require the module within thread A and then later spawn thread B from the main thread, thread B would have to also require the module before using it.

Someone (I think renodino), has mentioned that he has (or is working on) a module that allows you to share objects across threads. I am unsure of the details of how this works or if it requires require in all sharing threads. Doing a supersearch for "shared objects" may turn up the appropriate threads and further information.

Be wary of using any modules in the Thread::* namespace. Some (like Thread::Queue) are just fine in conjunction with threads. Some others are remnents from perl5005 threads and do not work with threads. Still others attempted to bridge the transition from 5005threads to ithreads in the early days of ithreads and never quite got finished.

Unfortunately, there is no way apart from trial and error to work out which modules fall into which category. I sorely wish that the entire Thread::* namespace would be dropped or deprecated and any ithreads-capable modules would be moved into the threads;:* namespace--but I doubt it will ever happen.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Share symbol table between threads
by renodino (Curate) on Oct 04, 2006 at 15:08 UTC
    Someone (I think renodino), has mentioned that he has (or is working on) a module that allows you to share objects across threads.

    Yes. See Thread::Apartment. I have successfully used it for a number of projects, including HTTP::Daemon::Threaded, and Tk::Threaded (tho the latter has some issues w/ tie()'d variables that keep me from CPANing it yet). I've also used the same general concepts for DBIx::Threaded, tho it needs to be updated to migrate to Thread::Apartment...or actually, a variant of Thread::Apartment I hope to build atop Thread::Sociable once its completed.

    Caveat: This isn't truly "sharing", but rather "proxying", ala Microsoft's COM model.