Hi Monks,

We have multiple host servers which are pinging continuously and stored in a hash format like key and value pairs.

Key and Values are different Hosts.

If the host is not pinging(DOWN), We have to remove the element from the hash and after removing the element from the hash we have opened the thread , which will run continuously till the host is pining(UP).

Once the host is pinging(UP), We need to add the pinging host element into the hash and thread will be closed for this host.

We have successfully updated(remove/add) the hash element before opening of any thread but after opening the thread we are unable to update(add/remove) the hash element.

Please help me why the hash element is not updating inside the thread loop?

below is the flow of code:
while(1)
{
   foreach $ESX (keys %hash)
   {
      &ping();
    }
}


sub ping()
{
   if(pinging)
   {
      return. ### host is pinging
   }
   else
   {
      1) We have removed the element from the hash
      UPDATE THE HASH ELEMENT
      3) Opened the thread, &ping_thread() (this thread will run continuously till the host is pinging.
   }
}


sub ping_thread()
{
    if(pinging)
   {
      add the elements to the hash
      UNABLE TO UPDATE THE HASH?
      return up;
   }
   else
   {
      while(1)
      {
         pinging time intervals
         val=&ping_thread();
         if(val eq up)
         {
             return the thread;
         }
       }
   }
}


Please help me why the hash element is not updating inside the thread loop?


TIA.

In reply to update the hash element in side the thread loop by nagivreddy93

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.