in reply to Should I use threads? Perl/DHCP/Radius
Threads are the perfect solution for this type of problem, where you need some realtime sharing between the threads. The only thing I would add, to yours and BrowserUk's solutions, would be to add an eventloop system in your main program, which can utilize timers to check shared variables on a regular schedule, and do what needs to be done. The threads:shared code already has locking shared variable locking available to you, but if you think about it, you can give each thread it's own hash slice to write to to avoid locking, then have the timer in the main program loop do periodic checking of the hash. Event loops can be done with POE, Tk, Gtk2, GLib, Wx, and many other eventloop systems.
For instance, see Tk-with-worker-threads and Threads-w-Perl/Gtk2 demo and the POE Cookbook. For an example of sharing socket filehandles amoung threads, see Simple threaded chat server
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Should I use threads? Perl/DHCP/Radius
by BrowserUk (Patriarch) on Aug 23, 2010 at 18:48 UTC | |
by zentara (Cardinal) on Aug 24, 2010 at 12:03 UTC | |
by BrowserUk (Patriarch) on Aug 24, 2010 at 12:32 UTC | |
by zentara (Cardinal) on Aug 24, 2010 at 12:36 UTC | |
by MonkeyMonk (Sexton) on Aug 24, 2010 at 13:42 UTC | |
by BrowserUk (Patriarch) on Aug 24, 2010 at 13:59 UTC | |
by zentara (Cardinal) on Aug 25, 2010 at 14:32 UTC | |
by BrowserUk (Patriarch) on Aug 25, 2010 at 14:38 UTC | |
|