Re: [xml] threads and xmlInitParser
- From: Daniel Veillard <veillard redhat com>
- To: Fredrik Arnerup <e97_far elixir e kth se>
- Cc: xml gnome org
- Subject: Re: [xml] threads and xmlInitParser
- Date: Sun, 14 Sep 2003 07:24:33 -0400
On Sun, Sep 14, 2003 at 12:05:33PM +0200, Fredrik Arnerup wrote:
Hello,
I had a threading related problem with the saxparser that I managed to
resolve by putting a call to xmlInitParser() in main().
However, the problem also disappeared when I put a call to xmlInitParser()
inside each thread before starting the parser.
I realize this is not what the docs say I should do, but can I expect
xmlInitParser() to work even if it is called from a separate thread and can
I call it more than once?
----------------------
static int xmlParserInitialized = 0;
/**
* xmlInitParser:
*
* Initialization function for the XML parser.
* This is not reentrant. Call once before processing in case of
* use in multithreaded programs.
*/
void
xmlInitParser(void) {
if (xmlParserInitialized != 0)
return;
----------------------
I think it's pretty clear that calling it in concurrent threads while
not initialized introduce a hazard. Don't do that ! Moreover the function
doc says so too so really don't do that !!!
Once initialized you can call it to your heart content until
someone calls xmlCleanupParser() which no thread should ever do.
This allocates memory, including parser entities, make sure it's called
at the beginning in a thread aware application, and call xmlCleanupParser()
only when nobody uses the library or XML documents anymore, and if
you can't be sure do not call it.
I ask partly for my own sake and partly because I hope to produce a patch
that would make libxml++ more thread safe.
The very basis for a library code would be to conform the way the
API intends to be used i.e. as documented. Again call it at init time !
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]