RE: [xml] [Q] libxml-2.2.2.3 Thread Safe ?

Date view Thread view Subject view Author view

From: Marc Sanfacon (sanm@copernic.com)
Date: Thu Sep 28 2000 - 16:18:02 EDT


from ?
>
> I have begun to trace the code, but there are lots of code, so any pointer
> would be really appreciated.

  Hummm interesting
  parser functions uses the parsing context for their informations
Since it's HTML parsing the entites stuff should not give problems.
You should try to focuse on the global variables, they are likely to
come from HTMLparser.c parserInternals.c or the xmlIO.c modules ...
There should have that many.

  Good luck, those kind of bug chaing are hard :-(, tell us what you
find and on't hesitate to ask for more informations ... I would really
like this bug to be found because I have tried to design it to be
thread safe at least at parsing time.

  Check that the allocation/feeing functions a re thread safe, if needed
override them with thread-safe routines (there is a function for this
exported in xmlmemory.h).

Daniel

--------------------

Hi Daniel,
        I continued my work on that today. I identified the difference
between the 2 generated xml tree, one in ST and the other in MT. The
difference I can see is that in the MT tree, some of the nodes are not
positionned under the same node as the one in ST. They are indented one
node more in the MT trees. Not all the nodes, sometimes just one.

So I found this problem in HTMLParser.c

void
htmlInitAutoClose(void) {
    int index, i = 0;

    if (htmlStartCloseIndexinitialized) return;

    for (index = 0;index < 100;index ++) htmlStartCloseIndex[index] = NULL;
    index = 0;
    while ((htmlStartClose[i] != NULL) && (index < 100 - 1)) {
        htmlStartCloseIndex[index++] = &htmlStartClose[i];
        while (htmlStartClose[i] != NULL) i++;
        i++;
    }

    /* NEW LINE */
    htmlStartCloseIndexinitialized = 1;
}

    htmlStartCloseIndexinitialized = 1; wasn't there, so the index was
initialisez every time. In my case, since I call the parser in ST first,
with this fix, I seemed to have solve my multi-thread problem !!!! Of
course, there are a few places, that some initializations are done the first
time that can cause a problem if no mutexes or sync mecanism are placed
there, a problem can occur.

htmlInitAutoClose is one such place.

int htmlParseDocument(htmlParserCtxtPtr ctxt) {
    xmlDtdPtr dtd;

    htmlDefaultSAXHandlerInit();

Is another place. Why do we need to initalize 'htmlDefaultSAXHandler' here
? It was already initialized when instantiated. Am I right by saying that
it should not (must not) be modified by any function ? To be thread safe,
actually, every parsing should have its own context (which is true) and its
own sax handler, which in some cases seem not to be true.

I will continue my testing to be sure this does the trick. But for now, the
test has been running for 1 hour without a crash.

BTW, I am using a Dual computer (PIII-700) so, I should be able to find most
of the multi-thread bug.

Of course, As I said, since I call the parser in ST first, some of the bugs
might be there also. It would be a good idea to have an initialization
routine available, so I could call it when starting the system and ensure
all the globals variables are initialized.

Thank you.

Marc.

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Sep 28 2000 - 16:43:32 EDT