Thanks, I'll try these ideas.
My programs are in no way going into production :). These are just exercises so that I can understand how threads work in Perl. I appreciate the help. I think my next exercise will be a bit harder. I'm going to take a program I've done in threads in C and convert to Perl. It is a device monitor that uses simple ping to make sure devices are up. There is 1 thread that walks through the list of objects doing notification (email). There is a thread for each IP address. The whole idea of doing it in threads is so that we can guarantee that every 60 seconds we ping a host. If we simply walked through a list a couple of unreachable addresses could throw that guarantee out the window. In the C version I created a linked list of objects. Each thread worked on one object and the notification thread simply walked that list looking for things to act on. Hopefully I can get the Perl program to do the same thing :) On Tue, 2006-10-10 at 10:25 -0700, Dean Arnold wrote: > Dean Arnold wrote: > > Christopher Fowler wrote: > >> On Tue, 2006-10-10 at 09:23 -0500, Michael J. Pomraning wrote: > > > > I've done a quick rewrite of your example (note I have no idea what > > the function of your script is, but the Packet class is a pretty simple > > container > > class, so hopefully this captures what you're attempting). > > Big OOOPS on my part. I forgot one little detail: you have to rebless > the object when its dequeue'd: > > > > > sub process_thread { > > while(1) { > > > > # > > # wait for a packet (or for 'DIE') > > # > > my $pktobj = $q->dequeue(); > > # > > # if not a ref, then it must be 'DIE' > > # > > return 1 > > unless ref $pktobj; > > # > # You have to rebless in the receiving thread > # > bless $pktobj, 'Packet'; > > # > > # Get the packet off the list and unpack the time > > # > > my $pkt = $pktobj->get_packet(); > > my $ti = $pktobj->get_timestamp(); > > FWIW (and blatant plug): if your Packet class becomes more complex, esp. > if it has object refs or file handles as members, > you might check out Thread::Queue::Duplex, which provides a > Thread::Queue::Queueable base class which your Packet class can subclass > to implement its own marshalling/unmarshalling (aka curse()/redeem()) > methods to deal with recovering things. > > Dean Arnold > Presicient Corp.