in reply to Re^2: Should I use threads? Perl/DHCP/Radius
in thread Should I use threads? Perl/DHCP/Radius

If there was a requirement to "have the timer in the main program loop do periodic checking of the hash.", that is trivial:

Is what I am doing. But thanks for your advice folks! I am currently figuring out how to synchronize the thread for each MAC with the main thread. Should be interesting!
  • Comment on Re^3: Should I use threads? Perl/DHCP/Radius

Replies are listed 'Best First'.
Re^4: Should I use threads? Perl/DHCP/Radius
by BrowserUk (Patriarch) on Aug 24, 2010 at 13:59 UTC
    I am currently figuring out how to synchronize the thread for each MAC with the main thread.

    Could you explain why you need to do that?

      I am currently figuring out how to synchronize the thread for each MAC with the main thread.

      The concept is simple. Have a shared hash or array where each thread can write to a scalar. Have a timer ;-) in the main thread loop thru the hash, and make logical descisions for you.

      You have 2 ways of sending messages back from child thread to master thread. One is shared variables, two is thru the fileno's on the open filhandles( which all threads share). You can open a filehandle in the mainthread to listen to with a fileevent method, then have the spawned threads write to that filehandle so that the mainthread can listen for synchronization data.

      Also remember to save the tid's ( thread ids) as you spawn them, so your parent thread can join them later, to destroy them. Just Another Hash Problem. ;-) See Reusable threads demo for enlightenment. P.S. Read the replies for a higher level of enlightenment. :-)


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        Have a timer ;-) in the main thread loop thru the hash, and make logical descisions for you.

        Simple. And wrong!

        You're still trying to find a way to wield that lumphammer.

        Creating artifical events (polling), is *NEVER* the right approach to solving the problem. Is just spins cycles and wastes resources.