For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > Passing objects between threads.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Passing objects between threads.
Bryan Balfour

2005-07-25, 9:24 am

I'm new to Perl and have been playing around with Thread. Can some kind
soul tell me if references to objects can be queued in one thread to be
dequeued in another? When I try it the dequeued reference is different
to the queued reference and I can't understand why this is so.

If it is possible, a code snippet would be appreciated.

Thanks.

Bryan Balfour

2005-07-25, 5:30 pm

Expanding on my original question;

The core of my application is a wait loop that waits on the 'work
queue' (Thread::Queue) upon which 'work-units' are enqueued. A
'work-unit' is an instance of my "WorkUnit" class in which the data
relevant to that 'work-unit' is stored.

Prior to dropping into this wait loop, my application creates a new
instance of a class responsible for capturing a line of keyboard input,
loading it into a new work-unit and queuing this work unit onto the
'work queue'.

This is achieved asynchronously by the constructor of this class
creating a new thread (which is then detached). The parameters passed
to this class on the constructor are references to the 'work queue',
the locking flag and the wait/pulse event.

When this application runs, work-units containing keyboard input are
successfully queued in the 'keyboard input' thread. The problem is that
when these work-units are dequeued in the wait loop, they are empty.
The 'ref' function returns "WorkUnit" as their type but they have not
been initialised so I'm getting 'uninitialised value' errors when I try
to retrieve the 'work-unit' data.

Other points that may be relevant are:

- I'm running Perl 5.8.6 under WindowsXP

- My main application uses the following classes:

Thread qw(async);
Thread::Queue;
Thread::Semaphore;
Win32::Event;

- I don't really understand how Perl works.

Hope this helps.

Bryan

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com