Having trying myself to implement a semaphore-based locking mechanism for
IPC SysV shared memory, I'd recommend IPC::ShareLite for general purposes.
It comes with a powerful locking mechanism,
which is incredibly similar to flock() ! Apache::SharedMem also depends on this module.