mutual exclusion Q
am 01.12.2008 03:49:59 von Craig or Merikay MacKennaMy 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