Is it possible to call a parser from libxml from several asynchronous network calls?

I have a piece of code that uses NSURLConnection to asynchronously retrieve a network resource and parse some XML in its stream. XML parsing is handled by libxml2, which is available as a framework in the iOS SDK. This works fine when I call it once, parse the XML and free the resources by calling xmlFreeParserCtxt (ctxt).

My problem is that when I run the same code on multiple threads, EXC_BAD_ACCESS suddenly appears and I return to libxml2. In particular, the xmlParserCtxtPtr context that is initialized and used for XML parsing seems to throw EXC_BAD_ACCESS when I release it after I have finished searching for the resource. The exception is thrown if I do not release this context, i.e. call xmlFreeParserCtxt (ctxt).

It makes me think that my problems are related to the fact that those related to libxml frames available in iOS are not thread safe.

Of course, I see this when I have a problem: From: http://xmlsoft.org/threads.html

Starting with 2.4.7, libxml2 provides guarantees that parallel streams can work safely when analyzing different documents in parallel. However, there are several things to do this:

* configure the library accordingly using the --with-threads options
* call xmlInitParser() in the "main" thread before using any of the libxml2 API (except possibly selecting a different memory allocator)

I have two questions: 1.) Is my assumption correct that the version of libxml that I am using is not thread safe and therefore causes a problem? Has anyone else seen this? 2.) I know that iOS binds libxml2.2.x - will it work if I get libxml2.4.7 and add it to my project? Due to any failures in the application store?

Thank you for your time.

+3
source share

Source: https://habr.com/ru/post/1767107/


All Articles