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


In reply to XML::LibXML and threads by philou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.