This is a bit of a logic issue, and I can't quite see my way through it at the moment.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.