Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

mutual exclusion Q

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


mackenna at animalhead

Nov 30, 2008, 6:49 PM

Post #1 of 2 (392 views)
Permalink
mutual exclusion Q

My Q today may be affected by Apache and/or Perl, so it seems
appropriate for this mailing list.

I've written a mod-perl module that needs mutual exclusion among
Apache child processes using the prefork MPM, so I decided to use a
file as a semaphore using Perl's 'flock'.

1. The mutual exclusion doesn't work (in the sense that multiple
processes are allowed to execute mutually-excluded code
simultaneously) if the post-config phase (before forking) just
sysopens the file for write with permissions 0666, and the child
processes flock the resulting filehandle ($outer_lock_fh) when they
need to.

2. It works if the post-config phase does the same sysopen (to ensure
the file exists) and then immediately closes the file, and each child
process opens the file for input in its child-init phase.

3. Mutual exclusion does not work (in the same way as in 1) if the
post-config phase sysopens for write, closes, and then opens for
reading in the same way that the child-init phases do in case 2.

This suggests that the forking operation (with demotion to a lower
priority user) prevents flock from working properly on the inherited
filehandle. Yet my Apache child processes can inherit other open
filehandles and tied hashes from the original process, and do I/O via
them just fine, without having to re-open them.

Can anyone this difference in use of these filehandles? If I could
understood why 1-3 act as they do, this would probably help me in the
future.

Thanks,
cmac
www.animalhead.com


perrin at elem

Dec 1, 2008, 1:01 PM

Post #2 of 2 (336 views)
Permalink
Re: mutual exclusion Q [In reply to]

On Sun, Nov 30, 2008 at 9:49 PM, <mackenna [at] animalhead> wrote:
> This suggests that the forking operation (with demotion to a lower priority
> user) prevents flock from working properly on the inherited filehandle. Yet
> my Apache child processes can inherit other open filehandles and tied hashes
> from the original process, and do I/O via them just fine, without having to
> re-open them.

I don't think that's correct. If you're sharing read/write
filehandles between processes and you haven't had problems, you're
just getting lucky. You need to open them in each child process.

- Perrin

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.