[xml] race conditions in libxml2



Hi,

I have the following pretty simple program:

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <libxml/parser.h>
#include <libxml/catalog.h>
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
    
static const int kHTMLParseFlags = 
    HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR |           HTML_PARSE_NOWARNING | HTML_PARSE_NONET;
    
void* test1(void* ptr) {
    htmlDocPtr doc = htmlReadFile("http://www.google.com", NULL, kHTMLParseFlags);
    xmlFreeDoc(doc);
}
    
void* test2(void* ptr) {
    htmlDocPtr doc = htmlReadFile("http://www.lenta.ru", NULL, kHTMLParseFlags);
    xmlFreeDoc(doc);
}

int main(void)
{
    xmlInitParser();
    xmlInitializeCatalog();
    pthread_t thread1, thread2; 
    pthread_create(&thread1, NULL,  &test1, NULL);
    pthread_create(&thread2, NULL,  &test2, NULL);
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);
    xmlCatalogCleanup();
    xmlCleanupParser();
    return EXIT_SUCCESS;
}
    
    
When I run it in `valgrind --tool=helgrind` it shows many race conditions. What is the reason for this? It seems that `libxml2` should be thread safe. I'm compiling with `gcc -I/usr/include/libxml2 temp.c -lxml2 -pthread`.

Thanks,
Hovnatan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]