On Wed, Aug 28, 2013 at 07:26:36PM +0200, Oliver Friedrich wrote: > Hello. > I have the following multi thread related problem. > > main(){ > xmlInitParser(); > //validationstuff > xmlParserCtxtPtr globalContext = xmlSchemaValidCtxtGetParserCtxt(ctxt); > } > > threadFunction(){ > xPathObjectPtr foos = xmlXPathEvalExpression ("foo", globalContext); > //read all the foos > } > (sorry I dont have the actual code here)
Your pseudo code makes no sense. In the first routine globalContext is of type xmlParserCtxtPtr, i.e. a context for parsing a document In the tread routines globalContext is of type xmlXPathContextPtr. > The program makes a lot of new threads and some of these segfault if > there are to many of them. So e.g. when I create 50 threads, approx. > 10 of them segfault - the rest don't. > > I first thought, I could fix this by using a globalDocPtr instead of > context and create a new context in each thread - but this will lead > to the segfaults. > > I could reduce the problem to the xmlXPathEvalExpression call (since > if I return before, everything wents fine). > Did I use the API wrong or what is the problem (at least as you can > say based on the piece of code)? You can have concurrent XPath evaluations, using each separate XPath evaluation context, but all of them pointing to the same *read only* document. Parse the document in main, allocate XPath contexts and run XPath queries in parallel on that shared document. Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veill...@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/ _______________________________________________ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml