Hello Torsten and Fred, So I looked at ithreads.pm (found it in an svn repository online http://svn.apache.org/viewvc/perl/modperl/trunk/t/response/TestPerl/) and from what I saw, my approach was theoretically the same as in the test module except that the threads were created after the shared variable was declared, which in my case was different. I decided to investigate Fred's suggestion of preloading my modules in startup.pl more closely. I remember doing that once but I guess I was a little careless because this time it worked. In order to solve my problem, I created startup.pl with the following code:
use strict; use warnings FATAL => 'all'; require threads; "threads"->import(); use U2D::TestSharing (); 1; Then I added PerlRequire startup.pl to my VirtualHost config and inserted sleep(1); before the line logTestMessage('Releasing lock.');. While running tail -f testSharing.log I saw that multiple threads answered the requests simultaneously and only one initialized the array. So Fred's suggestion of preloading the module was correct. Thank you very much for everyone's help. Anyone playing with the worker mpm in the future should take note: LOAD YOUR SHARED VARIABLES IN THE STARTUP.PL FILE BEFORE USING THEM IN THE HANDLERS!!! Sincerely, Pawel 2011/8/2 Torsten Förtsch <torsten.foert...@gmx.net> > > On Tuesday, 02 August 2011 20:24:46 Fred Moyer wrote: > > I haven't used the worker mpm, but it looks like you might want to > > preload your handler in the httpd parent process. > > Unlikely that that will help. threads::shared works by creating a > separate perl interpreter to keep the shared values. That interpreter > does not execute any program. It simply serves as shared storage. When a > variable is then marked as shared it is assigned magic to have the normal > accessor methods use the storage in the other interpreter. So, no matter > when the variable or the interpreter executing a program is created > shared variables are always fetched from the special storage interpreter. > > The special storage interpreter is a global variable at C-level. > > t/response/TestPerl/ithreads.pm in the modperl test suite exercises > shared variables. I'd take this as a starting point. First, I'd create a > simple shared scalar as a global counter. If that works (which I think it > does) the rest is how to use threads::shared correctly. > > As for your code I think you could try to push shared apples like this > > push(@fruits,share('apple')); > > Perhaps even > > push(@fruits,share(do {my $x='apple'})); > > Torsten Förtsch > > -- > Need professional modperl support? Hire me! (http://foertsch.name) > > Like fantasy? http://kabatinte.net