I would question the need to use threads for this project. As far as I can see, the threads merely read what appears to be a 1-line file, and print, for each loop. There does not seem to be any "event" the thread waits on, other than a pre-specified timer.

If this is an exercise (which is a laudable goal), I would approach using the threads differently.

Avoid shared variables unless absolutely necessary. The only thing the threads need to be told is when to quit. You can pass that information using a Thread::Queue. Any data collected by the thread can be returned by the same mechanism. Working thread code using Queues, is available here.

Each thread would read the queue in NON-BLOCKING mode, and quit if a message is received.

The main thread would queue in THREADCOUNT messages, when it was time to quit.

You also had additional requirements (in a separate post). If thresholds are breached, you can use the same thread to communicate the breach back to the main thread. That would then perform the appropriate action. This way, the thread code can be clean, and minimal.

I would also suggest you let perl read the files, instead of doing "CAT".

     "How many times do I have to tell you again and again .. not to be repetitive?"


In reply to Re^3: Global objects? by NetWallah
in thread Global objects? by Gilles0181

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.