here is my current code (which works). Don't know about mem leaks however...
#!/usr/bin/perl -w use strict; # Amen use threads; use threads::shared; #-------------------------------------------------- # Application includes #-------------------------------------------------- use person; #-------------------------------------------------- # Forward declarations #-------------------------------------------------- sub doTemp1; sub doTemp2; sub doQuit; #-------------------------------------------------- # Local variables #-------------------------------------------------- our $intDelay : shared; # One-wire delay our $blnRunning : shared; # Signal boolean our $intThreadCount : shared; # Holds the number of threads active our %hshSensors : shared; # Sensor hash our $OWFS : shared; # Main application our $OWFS_MOUNT : shared; # Mounting point $SIG{HUP} = \&doQuit; $SIG{INT} = \&doQuit; $SIG{TERM} = \&doQuit; $SIG{CHLD} = 'IGNORE'; # Ignore child processes to prevent zomb +ies $OWFS = "/opt/owfs/bin/owfs"; $OWFS_MOUNT = "/var/1-wire"; #-------------------------------------------------- # Start application #-------------------------------------------------- $intDelay = 5; $intThreadCount = 0; $blnRunning = 1; # Start polling `echo 1 > $OWFS_MOUNT/simultaneous/voltage`; `echo 1 > $OWFS_MOUNT/simultaneous/temperature`; # Start thread for monitoring threads->new(\&doTemp, "Temperature 1", "10.D76B5A010800", 30, 0.2, "" +); threads->new(\&doTemp, "Temperature 2", "10.FB865A010800", 25, 0.2, "" +); # Just something to keep the script rolling in the background while (1) { sleep 3600; }; #-------------------------------------------------- # Thread sub sub doTemp { my ($strTitle, $strDevice, $dblNominal, $dblHysteris, $strStatus) += @_; my ($dblCurrent, $dblHigh, $dblLow); # Increment thread count $intThreadCount++; # Initialize values $dblCurrent = 0; $dblHigh = ($dblNominal + $dblHysteris); $dblLow = ($dblNominal - $dblHysteris); # Start main loop while ($blnRunning) { # Poll sensor $dblCurrent = `cat /var/1-wire/uncached/$strDevice/temperature +`; $dblCurrent =~ s/^\s+//; $dblCurrent =~ s/\s+$//; if ($dblCurrent) { if ($dblCurrent >= $dblHigh) { $strStatus = "TOO HOT ($dblCurrent / $dblHigh)"; } elsif ($dblCurrent <= $dblLow) { $strStatus = "TOO COLD ($dblCurrent / $dblLow)"; } else { $strStatus = "WITHIN RANGE ($dblCurrent)"; } # Dump data print "-> ($intThreadCount) $strTitle: $strStatus\n"; } sleep $intDelay; } # Decrement thread count $intThreadCount--; # Bail thread print "-> Polling of $strTitle stopped.\n"; } # Closes current server and bails out sub doQuit() { $blnRunning = 0; # Close threads which are running print "-> Waiting for destruction\n"; while ($intThreadCount > 0) { sleep 1; } print "-> Server destroyed\n"; exit; }

In reply to Re^2: Global objects? by Gilles0181
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.