Created
January 2, 2014 17:35
-
-
Save pdl/8222887 to your computer and use it in GitHub Desktop.
Using Threads and XML::LibXML appears to cause a memory allocation bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use threads; | |
use Thread::Queue; | |
my $q = Thread::Queue->new(); # A new empty queue | |
my $q2 = Thread::Queue->new(); # A new empty queue | |
use XML::LibXML qw(:threads_shared); | |
my $parser = XML::LibXML->new; | |
my @docs = | |
map { $parser->parse_string(qq{<root><foo id="$_">bar</foo></root>}) } | |
1..10 | |
; | |
# Worker threads | |
my $getter = threads->create( | |
sub { | |
# Thread will loop until no more work | |
while (defined(my $item = $q->dequeue())) { | |
# $q2->enqueue($item); | |
$q2->enqueue( $item->documentElement->findvalue('//foo/@id')); | |
} | |
$q2->enqueue (undef); | |
} | |
); | |
my $printer = threads->create( | |
sub { | |
# Thread will loop until no more work | |
while (defined(my $item = $q2->dequeue())) { | |
print "\n".$item; | |
} | |
} | |
); | |
$q->enqueue(@docs); | |
$q->enqueue(undef); | |
$printer->join(); | |
$getter->join(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment