I have a main program that calls 7 other programs in parallel (this logic has be resolved). I am passing to each of these programs, by reference, a flag variable, called $lock. In each of the sub-programs, they are checking the value of $lock. The sub-program will only act if $lock is false, but will wait until the condition is set to false.
My issue is this: If I start with $lock set to false, then my test while ($lock) { never activiates. But, if I use while(!($lock)) {, then I never really properly do the check, and the section of code will skip.
flock() is not an option for this, as this program will need to be able to be run by multiple users at the same time. flock() would be working on the same file for every user, so it would be contending with itself.
So, how to I keep all the sub-programs from acting all at once, and avoid none of them ever acting at all because they are all waiting indefinately for something to happen?
Addnedum: I have figured out the code to work this through. It involves testing to see if the lock is on or off, then waiting if the lock is on, and just going ahead if the lock is off. My issue now seems to be that if I pass the reference to $lock, the value of that reference does not seem to go with it. The sub-programs are called (forked) off the main program, with the reference to $lock passed as an argument.
In reply to Logical Conundrum by mcogan1966
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |