igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Multithreading and GraphML


From: Chris Wj
Subject: Re: [igraph] Multithreading and GraphML
Date: Wed, 19 Aug 2009 09:23:39 -0400

Your solution is definitely a better one. I would rather either a.) call it explicitly if there is any other need for such a call or will be in the future or b.) have some sort of reliable preprocessor conditional that puts in a call to the xmlInitParser function if both multithreading support and xml support is enabled. I expect that this crash will occur for any c-based multithreaded application as well. Although those applications could call the xmlInitParser function themselves.

I've done some testing with it as a temporary fix in the igraph_read_graph_graphml function, which, in my program, gets called in a thread that is not main. So far it works well and the crash is gone. I believe the global locking it does performs the necessary setup it needs from that point on. If it does not do this on first run globally for all threads, then it is a performance loss as the setup would need to fully run for each thread. I will continue to read through the libxml2 code today to get a better understanding of what exactly is done during the init/setup.

On Tue, Aug 18, 2009 at 6:49 PM, Tamas Nepusz <address@hidden> wrote:
Hi Chris,

Thanks for reporting and fixing that. My only concern is that you cannot be sure that igraph_read_graph_graphml is called in the "main" thread, so xmlInitParser() may be called from a different thread. I don't know if that matters to libxml2 or not, but the webpage states that xmlInitParser() must be called from the main thread. Do you have any comments on that? If it really matters, then we should maybe add an extra igraph_init() function to the library and make sure that Python calls it when it loads the igraph module.

--
Tamas



On 2009.08.18., at 22:19, Chris Wj wrote:

Hi all, this is just a FYI for anyone working with igraph and doing multithreading. I fixed a bug where igraph crashes in multithreaded apps using libxml2 by adding the following line to 'foreign-graphml.c', line 997 in 'igraph_read_graph_graphml' after the variable declarations.

xmlInitParser();

>From http://xmlsoft.org/threads.html:
call xmlInitParser() in the "main" thread before using any of the libxml2 API

While  'igraph_read_graph_graphml' may be called multiple times, I checked the 'xmlInitParser' function to find this source:
void
xmlInitParser(void) {
   if (xmlParserInitialized != 0)
   return;
 #ifdef LIBXML_THREAD_ENABLED
   __xmlGlobalInitMutexLock();
   if (xmlParserInitialized == 0) {
...

Where it a) locks on __xmlGlobalInitMutexLock(); and b) subsequently sets xmlParserInitialized to 1, so calling it multiple times doesn't really hurt (I am fairly sure of this and will report back if otherwise).

This bug manifested itself using the Python library and Python threads, which are pthreads after all.

-Chris
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


reply via email to

[Prev in Thread] Current Thread [Next in Thread]