New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread safe Xerces-C setup / termination. #924
Conversation
A new Pull Request was created by @ktf (Giulio Eulisse) for CMSSW_7_0_X. Thread safe Xerces-C setup / termination. It involves the following packages: FWCore/Concurrency @smuzaffar, @Dr15Jones, @ktf, @nclopezo can you please review it and eventually sign? Thanks. |
Does XMLPlatformUtils::Initialize already do a counter so if there are multiple XMLPlatformUtils::Initialize only the first goes off and if there are multiple XMLPlatformUtils::Terminate() only the last sets it off? |
// use a global mutex to serialize everything. | ||
void xercesInitialize() { | ||
std::unique_lock<std::mutex> l(g_xerces_mutex, std::defer_lock); | ||
l.lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why defer_lock since your next line is l.lock()
?
See http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-6 for the limitations on Xerces-C.
I initially had two locks, but that was clearly useless... I cleaned it up... |
Pull request #924 was updated. @smuzaffar, @Dr15Jones, @ktf, @nclopezo can you please check and sign again. |
I guess my question was unclear. What Does Xerces do if I do XMLPlatformUtils::Initialize();
XMLPlatformUtils::Initialize();
XMLPlatformUtils::Terminate();
XMLPlatformUtils::Terminate(); Does it actually wait for the second call to Terminate before actually terminating xerces? |
I was replying to your other comment (why the deferred lock). Your example above will work correctly (multiple initialize are fine, last terminate will terminate), however you need to guarantee that Terminate is not called by someone while someone else is calling Initialize, this is why I'm serializing both with the same mutex: to guarantee atomicity. |
+1 |
This pull request is fully signed and it will be integrated in one of the next IBs unless changes or unless it breaks tests. @ktf can you please take care of it? |
This pull request is fully signed and it will be integrated in one of the next IBs unless changes or unless it breaks tests. @ktf can you please take care of it? |
Merging this since we all agree. I'll fix all the related bit in a separate pull request. |
Thread safety -- Thread safe Xerces-C setup / termination.
See http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-6 for the limitations
on Xerces-C.
I ended up to use a single mutex both for initialization and termination because I need to guarantee the following:
@Dr15Jones, if you agree with the implementation, I can go ahead and clean-up all the bits which call the original Xerces-C functions.