Doing it like this is the only safe way to guarantee that Init/Term are 
thread-safe though because we know that the static mutex instance will be 
initialized before any calls can be made into the library. And honestly, if the 
static global mutex object fails to initialize a synchronization primitive 
(pthreads on UNIX, InitializeCriticalSection on Windows, etc..), then don't you 
have _much_bigger_ problems to deal with? 

Disclaimer: I have no familiarity with platforms other than some UNIX/ish 
platforms (linux, solaris, aix, hp-ux) and Windows, and I'm not sure how many 
platforms Xerces supports, so perhaps for certain platforms, you simply can't 
do it this way because of OS limitations. But my naive opinion of those 
platforms that can't provide such guarantees would be that they're inherently 
broken :). 

Thanks,
Brandon

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: May 18, 2005 9:56 PM
To: [email protected]
Subject: Re: Protect XMLPlatformUtils::Initialize and
XMLPlatformUtils::Terminate


> This post is in regards to a bug that has been in the system for a
> long time:  http://issues.apache.org/jira/browse/XERCESC-42
> (XMLPlatformUtils::Initialize and XMLPlatformUtils::Terminate are not
> thread safe). My question is why can't the Initialize and Terminate
> functions be made thread-safe with the synchronization primitives
> that Xerces contains already (i.e. XMLMutex and XMLMutexLock)?

It's a chicken-and-egg problem.  XMLPlatformUtils::Initialize() creates 
the global synchronization mutex that it needs to synchronize.  Using a 
static instance of XMLMutex, as in your example, is not a good idea, since 
the library would not be able to recover from a failure to create the 
underlying platform-dependent synchronization object that XMLMutex depends 
on.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to