(AS 5.8.6, WinXP Pro)

I've got a fairly large scale threaded app (using Thread::Apartment) that is configured as a Win32 Service via Win32::Daemon. I've isolated all the Win32 Service stuff to a Singleton apartment threaded container object named Win32Service.

Creating, starting, and querying the service works fine. However, whenever the container object attempts to access a threads::shared structure after calling Win32::Daemon::StartService(), all threads::shared objects seem to lose their tie; here's an error reported after wrapping an eval { } around the reference to the threads::shared hash:

Can't locate object method "FETCH" via package "threads::shared::tie" +at C:\Perl\MyPerlDaemon/Win32Service.pm line 237.
Note that the rest of the threads in the app (which do not reference Win32::Daemon::StartService()) retain their threads::shared access - to the same structure that fails in the Win32::Daemon container object.

Does anyone have any idea what would cause a threads::shared object to lose its tie under these circumstances ?

Update:

Once again, a bit more digging uncovers a solution (tho not an explanation of the root behavior). In my original implementation, Win32::Daemon::StartService() was called before the threads::shared structure was created and instantiated in the Win32Service thread object. On a whim, I decided to create the shared structure before starting the Win32 Service, and install it as a class variable in Win32Service. Lo and behold, it now works just fine.

Note that I've used Thread::Apartment and Thread::Queue::Duplex to pass shared objects created long after the receiving threads are created. That ability is key to Thread::Apartment operation, in order to create thread pools early to limit the amount of context cloned into threads, and then pass threads::shared client proxy objects around for inter-object interfaces. So I can only assume that Win32::Daemon does something unexpected with the threads::shared code (as BrowserUk has suggested).


In reply to Odd threads::shared behavior within a Win32::Daemon app by renodino

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.