Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dequeue an array in perl with thread::queue

I am trying to process data with a set of threads and enqueue it with another, currently the enqueueing and dequeueing process doesn't seem to be working

Any thoughs??

sub process() {
    while (my @DataElement = $DataQueue->dequeue()) {
        print "\t".$DataElement[0]."\n";
    }
}

I use the following to enqueue the data


my @l;
push(@l, $directories.$suffix);
push(@l, "testclass");
push(@l, $eachFile);
$DataQueue->enqueue(\@l);
like image 984
Bob Avatar asked Aug 23 '26 19:08

Bob


2 Answers

Are you accessing an array reference without dereferencing it? Try

while (my $DataElementRef = $DataQueue->dequeue()) {
    my @DataElement = @$DataElementRef;
    print "\t".$DataElement[0]."\n";
}
like image 155
mob Avatar answered Aug 26 '26 19:08

mob


@l is not shared, so you can't pass it's reference to another thread. Use threads::shared.

like image 45
Telek Avatar answered Aug 26 '26 19:08

Telek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!