You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Brandon White <Br...@businessobjects.com> on 2005/05/19 06:18:42 UTC

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)?

With those classes, it should be as simple as doing something like this to prevent multiple threads from stomping on one another during platform initialization and termination.

In PlatformUtils.cpp:

static XMLMutex g_InitTermCS;
...

void XMLPlatformUtils::Initialize()
{
    XMLMutexLock (&g_InitTermCS);

...
}

void XMLPlatformUtils::Terminate()
{
    XMLMutexLock (&g_InitTermCS);
...
}

Is there any reason why this wouldn't be acceptable? It would prevent clients from having to worry about synchronizing requests to these calls in Xerces. I noticed from the mail archives (after a brief scan of them) that this issue has come up a few times:

- http://marc.theaimsgroup.com/?l=xerces-c-dev&m=108610609811439&w=2
- http://marc.theaimsgroup.com/?l=xerces-c-dev&m=103237127302800&w=2


Thanks,
Brandon

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Protect XMLPlatformUtils::Initialize and XMLPlatformUtils::Terminate

Posted by Axel Weiß <aw...@informatik.hu-berlin.de>.
Brandon White wrote:
> Is there any reason why this wouldn't be acceptable? It would prevent
> clients from having to worry about synchronizing requests to these
> calls in Xerces.

Hi Brandon,

where is the problem? You just can initialize xerces right before 
creating any new threads, and terminate after the last thread has 
terminated, respectively. Or what did I miss ...?

Regards,
			Axel

-- 
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
** www.freesp.de **

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Protect XMLPlatformUtils::Initialize and XMLPlatformUtils::Terminate

Posted by da...@us.ibm.com.
> 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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org