Skip Menu |
 

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 74542
Status: open
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: stevenwh.lee [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.0401
Fixed in: (no value)



Subject: Lazy attributes don't work with ithreads
Download (untitled) / with headers
text/plain 1.2k
The following sample code is to demonstrate the problem. It consists of a pipeline where the first thread creates some Moose-based objects and puts them in the queue, which are then picked up in the second thread. The problem is when it tries to get an attribute which is lazy built. package Foo; use Moose; has 'bar' => ( is => 'ro', isa => 'ArrayRef', # the error doesn't happen with simple scalar datatypes lazy => 1, # this line causes the error default => sub { [1 .. 10] }, # the error also occurs if this was a builder ); package main; use threads; use Thread::Queue; my $threadq = Thread::Queue->new; sub create { $threadq->enqueue( Foo->new ) foreach 1 .. 5; $threadq->enqueue( undef ); return; } sub process { while (my $f = $threadq->dequeue) { print @{$f->bar}, "\n"; } return; } threads->create( \&create )->join; threads->create( \&process )->join; This code results in the following error message: Show quoted text
> Thread 2 terminated abnormally: Invalid value for shared scalar > at reader Foo::bar (defined at ... line 9) line 10.
The error disappears if I remove the lazy property for that attribute. I ran this with Strawberry Perl 5.12.3.
From: stevenwh.lee [...] gmail.com
Download (untitled) / with headers
text/plain 1.6k
This bug report looks to be invalid. The error could be resolved by using Thread::Queue::Any instead of Thread::Queue to have the object serialised when being passed around. On Mon Jan 30 20:30:30 2012, https://www.google.com/accounts/o8/id? id=AItOawmNFe6WVyHDuaPnrLY6HWench7ziT_Uo2k wrote: Show quoted text
> The following sample code is to demonstrate the problem. It consists
of Show quoted text
> a pipeline where the first thread creates some Moose-based objects and > puts them in the queue, which are then picked up in the second thread. > The problem is when it tries to get an attribute which is lazy built. > > package Foo; > use Moose; > > has 'bar' => ( > is => 'ro', > isa => 'ArrayRef', # the error doesn't happen with simple > scalar datatypes > lazy => 1, # this line causes the error > default => sub { [1 .. 10] }, # the error also occurs if this > was a builder > ); > > package main; > > use threads; > use Thread::Queue; > > my $threadq = Thread::Queue->new; > > sub create { > $threadq->enqueue( Foo->new ) foreach 1 .. 5; > $threadq->enqueue( undef ); > return; > } > > sub process { > while (my $f = $threadq->dequeue) { > print @{$f->bar}, "\n"; > } > return; > } > > threads->create( \&create )->join; > threads->create( \&process )->join; > > This code results in the following error message: >
> > Thread 2 terminated abnormally: Invalid value for shared scalar > > at reader Foo::bar (defined at ... line 9) line 10.
> > The error disappears if I remove the lazy property for that attribute. > > I ran this with Strawberry Perl 5.12.3. >


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.