Hello,

I am running an Apache/2.2.17 (Ubuntu) with mod_perl 2.0 and Perl version 5.10.1. I created a module CitySearcher.pm that has a handler method to handle the request from the browser. The module has roughly the following format (simplified):

package CitySearcher; use strict; ... use Tree::Trie; use threads::shared; use APR::OS; my $TRIE :shared; my $TRIE_LOCK :shared = {}; sub handler { my $r = shift; $r->content_type('text/html'); ... my $request = new CGI; my $tid = APR::OS::current_thread_id(); lock($TRIE_LOCK); if(!defined($TRIE)) { print stream "$$-$tid: creating trie\n"; my $trie = new Tree::Trie; ... #populate $trie ... $TRIE = shared_clone($trie); } print stream "$$-$tid: returning trie\n"; ... #use trie ... return Apache2::Const::OK; } 1;

Then I restart the server and pound the server with about 25 calls within milliseconds to the page. Here is the ouput from the stream:

10320-3056253808: creating trie 10320-3056253808: returning trie 10320-3064646512: returning trie 10320-3056253808: returning trie 10320-3064646512: returning trie 10320-3064646512: returning trie 10320-3056253808: returning trie 10320-3064646512: returning trie 10320-3056253808: returning trie 10320-3064646512: returning trie 10320-3064646512: returning trie 10320-3022682992: creating trie 10320-3022682992: returning trie 10320-3047861104: creating trie 10320-3047861104: returning trie 10320-3056253808: returning trie 10320-3056253808: returning trie 10320-3022682992: returning trie 10320-3064646512: returning trie 10320-3031075696: creating trie 10320-3031075696: returning trie 10320-3064646512: returning trie 10320-3022682992: returning trie 10320-3056253808: returning trie 10320-3056253808: returning trie 10320-3039468400: creating trie 10320-3039468400: returning trie 10320-3022682992: returning trie 10320-3064646512: returning trie 10320-3056253808: returning trie

As you can see, thread 3056253808 initially creates the trie and then thread 3064646512 uses it too (no creating trie output). A little bit later thread 3022682992 comes along and creates a trie again. Why was the trie not shared? All threads are clearly running in the same process.

Thank you very much for your help.

Sincerely,

Pawel

SOLVED (I think):

I removed PerlInitHandler Apache2::Reload from my Apache configuration. Looks like the shared variables are removed when the Apache2::Reload module does its thing. I hope this tip helps anyone with a similar problem in the future.


In reply to On Apache server using mod_perl shared_clone does not produce shared object by busymeister

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.