> 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.
Not quite. That's _not_ what the C++ standard stipulates, and there are conforming implementations that do not initialize all of an application's statics at once. From section 3.6.2 of the standard: "It is implementation defined whether or not the dynamic initialization (8.5, 9.4, 12.1, 12.6.1) of an object of namespace scope is done before the first statement of main. If the initialization is deferred to some point in time after the first statement of main, it shall occur before the first use of any function or object defined in the same translation unit as the object to be initialized." Anyhow, nothing stops you from applying your method in your own software, as a layer above Xerces-C. One of our application does just this, because they don't mind failing miserably if the library doesn't initialize. Other applications probably have more stringent requirements. > 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 Yes, but that's not my point. If you rely on static initialization to do this, then how is Xerces-C supposed to notify you that initialization failed? Right now, it calls the installed PanicHandler if that happens, but it can't do that in your scheme. Should it call abort()? Possible, but not very robust. Should it set some global flag that everyone has to query? Possible, but pretty intrusive. Dave --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
