# So instead I tried the version in the comments on the # tutorial page although I don't really understand it :-(
A semaphore is like a rock sitting on the ground somewhere. Unless the process grabs the rock, it is not supposed to access the file. All the processes agree ahead of time that they won't try to access the file unless they have the rock. However, there is nothing preventing a rogue process from accessing the file directly -- the processes must take it open themselves to only access the file if they grab the rock first. When one process is done processing the file, it sets the rock down on the ground, and then the next process grabs the rock.
So a semaphore has nothing to do with locking a file per se; the semaphore is the rock, and the processes simply agree that they have to grab the rock before accessing the file.
I don't understand what code your Grid::Cluster processes are executing, so I can't help you there. It would probably behoove you to put aside the Grid::Cluster code and see if you can get locks to work on a simple program that spins off processes(or threads), which then sleep for a random amount of time before trying to write to a file. (Maybe that is what the second bit of code you posted is trying to do?)
See if you are making any of the mistakes described here:
http://perl.plover.com/yak/flock/In reply to Re: Threads and output files (locking)
by 7stud
in thread Threads and output files (locking)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |