hi all,

some days ago i already bothered you with one of my unnerving thread problems (a question on sharing data structures across threads), and thanks to BrowserUk and his patience with me the problem got solved so far. but still things don't behave as satisfactory as they ought to do, and i sometimes get unpredictable results. but first a sketch of the application's (an MMOG) architecture:

on an AMD64 box with a debian "lenny" system installation an apache 2.2.3 (mpm-worker) in combination with mod_perl2 serves perl-created html content on request. the backend consists of three parts: a MySQL 5.0.45 database, a perl (threaded) session server ("the engine"), which also processes all game events, and finally a cacheing daemon process, which became necessary since both the engine and apache have access to the same data. these data, rather huge structures too complex for keeping them in sql tables, are being kept on disk in form of plain files (serialized via Storable.pm). both apache and the engine communicate with this cacheing daemon via tcp/ip sockets on localhost. of course these sockets are IO::Socket::INET ones. and that's where my question begins.

because apart from the fact that sometimes (and on these occasions even stubbornly) the cacheing process simply doesn't receive any data at all - which i tried to bypass by locally undef'ing $/ and $\, and although i rather consider this as magic it apparently works - apart from that, sometimes the data get merged in ways that are plainly impossible. for instance chunks of data from one entity seem to appear somewhere else, where they don't belong to. the cacheing process cannot be the reason for these mistakes, since receiving and merging the data happens in the same (the main-) thread. but both mod_perl2 and the engine are threaded, and they instanciate for every connection to the cacheing daemon a new socket. IO::Socket::INET inherits from IO::Socket, which finally stems from IO::Handle. and the constructor from IO::Handle simply blesses a symbolic reference returned from Symbol::gensym. here's the respective code snippet from Symbol.pm:
my $genpkg = "Symbol::"; my $genseq = 0; [...] sub gensym () { my $name = "GEN" . $genseq++; my $ref = \*{$genpkg . $name}; delete $$genpkg{$name}; $ref; }
so finally the question: is that threadsafe? and if it isn't how could i make it threadsafe?

sry 4 the sermon. ;)
--------------------------------
masses are the opiate for religion.

In reply to yet another thread question: is Symbol::gensym threadsafe? by TOD

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.