Re: sharing objects
[email protected] ("Jack Steadman") Tue, 10 Oct 2006 15:10:37 -0400
| Newsgroups | perl.ithreads |
|---|---|
| Message-ID | <[email protected]> |
On 10/10/06, Dean Arnold <[email protected]> wrote: > Dean Arnold wrote: > Big OOOPS on my part. I forgot one little detail: you have to rebless > the object when its dequeue'd: > # > # You have to rebless in the receiving thread > # > bless $pktobj, 'Packet'; I've found it convenient to store the class name as a data member of the class and implement a simple 'rebless' function to automatically rebless shared objects when necessary. So for example: $obj = rebless($queue->dequeue()); sub rebless { my $obj = shift; return bless $obj, $obj->{'class_name'}; } You could even subclass or wrap Thread::Queue to do this automatically if you know that all of your queued items will be objects which follow this pattern. Jack