Christopher Fowler wrote:
> Thread 1:
>   Look for SYN packets and create a Packet object
>   Add that object to a list.
> 
> Thread 2:
>   Look through list looking for any Packet objects
>   Display to stdout the packet.
> 
> I am not getting the sharing part done write.  In order to share Packet
> do I have to create the constructor like I did?  What is the best
> practice for what I'm trying to do?

One line in your 'process_thread' sub looks typo'd to me:

>               my %p = shift @objs;

In any case, sharing your blessings can be tricky in perl.
(threads::shared/BUGS)  You might skip blessing to 'Packet' entirely --
it encapsulates only two data members in your test program -- and
instead pass an unblessed arrayref or hashref between threads.

I'd also recommend replacing the "@objs : shared" with a Thread::Queue
object, eliminating the need for sleep-poll behavior.

Good luck,
Mike

Reply via email to