philou has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I am trying to parse a few thousands of XML documents using multiple threads and XML::LibXML, but this always ends up in "Segmentation fault", with the following backtrace :
#0 0x0000000000000000 in ?? () #1 0x00002aaaab9d632b in __xmlParserInputBufferCreateFilename (URI=0x +1341e60 "src/local/surfex/OFFLIN/error_write_surf_bin.F90.xml", enc=X +ML_CHAR_ENCODING_NONE) at xmlIO.c:2633 #2 0x00002aaaab9ad20b in xmlNewInputFromFile__internal_alias (ctxt=0x +2aaaac9c99d0, filename=0x1341e60 "src/local/surfex/OFFLIN/error_write +_surf_bin.F90.xml") at parserInternals.c:1511 #3 0x00002aaaab9b0d04 in xmlCreateURLParserCtxt__internal_alias (file +name=0x1341e60 "src/local/surfex/OFFLIN/error_write_surf_bin.F90.xml" +, options=0) at parser.c:13964 #4 0x00002aaaab858bd2 in XS_XML__LibXML__parse_file () from /cnrm/gp/ +mrpm/mrpm609/install/yukisc2/perl-5.16.2/lib/site_perl/5.16.2/x86_64- +linux-thread-multi/auto/XML/LibXML/LibXML.so #5 0x000000000049b33f in Perl_pp_entersub () #6 0x0000000000499afe in Perl_runops_standard () #7 0x0000000000431e70 in Perl_call_sv () #8 0x00002aaaabde2c05 in S_ithread_run () from /cnrm/gp/mrpm/mrpm609/ +install/yukisc2/perl-5.16.2/lib/5.16.2/x86_64-linux-thread-multi/auto +/threads/threads.so #9 0x00002aaaab179193 in start_thread () from /lib64/libpthread.so.0 #10 0x00002aaaab34df0d in clone () from /lib64/libc.so.6
I am using perl 5.16.2 and libxml2 2.9.0, both configured with threads.
Here is what my perl code looks like :
use strict; use Data::Dumper; use XML::LibXML; use threads; my @file = <DATA>; chomp for (@file); my $n = shift () || 4; my @t = map { 'threads'->create (sub { for my $file (@file) { print "$file\n"; eval { my $d = 'XML::LibXML'->load +_xml (location => "$file.xml"); }; $@ && print "@=$@\n"; } print "done...\n"; return 0; } ) } (1 .. $n); for my $t (@t) { $t->join (); } __DATA__
I have written a pure C/libxml2/pthread program which does the very same thing, and it appears to work correctly, so I am stuck and do not have a clue on how to solve the failure in my perl script.
Does someone have an idea on what I should do to have XML::LibXML working with perl threads ?
Cheers,
Philippe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::LibXML and threads
by choroba (Cardinal) on Nov 28, 2012 at 11:01 UTC | |
by philou (Beadle) on Nov 28, 2012 at 11:57 UTC |