Re: [xml] initialization issues in libxml2



From veillard redhat com Tue May 20 08:48:42 2008

On Tue, May 20, 2008 at 08:24:17AM -0700, John Zolnowsky x69422/408-404-5064 wrote:
Daniel,

In Solaris, libraries mediating access to global data use static
initializers for the library-specific synchronization objects.  This
allows use of the library by multiple other libraries without requiring
application knowledge of the lower-level library.  For instance, in our
daemon, libxml2 is a third-level library being used to read
configuration information for a second-level library.  The application
is using a thread-safe first level library, and is unaware of the
second level-library or libxml2.  Likewise, the first-level library is
unaware of the the second-level library's use of libxml2.  For
applications using multiple libraries, each of which might be invoking
libxml2 for configuration unbeknownst to the application, there is no
obvious location for the preliminary call to xmlInitParser().

  Not having initialization routines for libraries and relying on
the loader to do the initializations sounds a very specific model,
I don't think you can expect that all the time.

It's not a property of the loader, but of the threads implementation.
Both the Solaris threads and the POSIX pthreads models provides for
this, allowing/encouraging the use of multi-threading even when the
application is unaware of it.  Failure to provide the equivalent of
pthread_once() might be considered a deficiency in other threading
models.

While I would urge you to relax this limitation on libxml2's thread
safety, I don't really know how feasible that would be for other
(non-pthread) threading models.  For our immediate needs for libxml2 in
Solaris, I expect we can provide a .init section invoking
xmlInitParser() and discourage the use of xmlCleanupParser() in
libraries and multi-threaded applications.

  That sounds the wrong approach to me, because then portable code using
libxml2 would have to initialize differently on Solaris than from other OSes.
Think for example to all those Apache modules, that's just not possible.
  Maybe we can find a way to make sure xmlInitParser() is not used in a
reentrant way (but since that's where all the thread specific data are
initialized that sounds like a challenge, the trick of using the loader to
bootstrap the sequence is unfortunately non portable and can't be relied
upon IMHO).

The issue isn't multiple calls to xmlInitParser(), but rather
simultaneous initial calls.  In effect, the call from the .init section
would be satisfying the requirement to 'call xmlInitParser() in the
"main" thread before using any of the libxml2 API.'  Any later explicit
calls by the application or internal to libxml2 to xmlInitParser() will
find xmlParserInitialized already set and simply return.

Perhaps I misunderstood your concern.  Are you worried about the
porting of applications and libraries using libxml2 from
Solaris/OpenSolaris to other platforms with more limited threading
models?

                                        -JZ

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
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]