I've tested flock on my webhoster, and if two processes try to simultaneously flock, the second one will wait until the first one has ended its lock before starting its own. The best way to do this is like originally suggested -
Open and lock a file (should be different from the file to be processed, so you can open and close that file multiple times if necessary without ending the lock)
Open file to be processed and do whatever
Unlock the lock file
I wrote myself small subs for locking and unlocking, and I just cut and paste them in wherever I need them. Saves time coding.