Skip to content
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

Merged
merged 1 commit into from Sep 27, 2013

Conversation

ktf
Copy link
Contributor

@ktf ktf commented Sep 26, 2013

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:

  • No thread can continue after Initialize (possibly invoking Xerces functionality) without at least one thread finishing the initialisation itself.
  • No thread can invoke Terminate while something else might be calling Initialise at the same time.

@Dr15Jones, if you agree with the implementation, I can go ahead and clean-up all the bits which call the original Xerces-C functions.

@cmsbuild
Copy link
Contributor

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.
@wmtan this is something you requested to watch as well.
You can sign-off by replying to this message having '+1' in the first line of your reply.
You can reject by replying to this message having '-1' in the first line of your reply.
@ktf you are the release manager for this.

@Dr15Jones
Copy link
Contributor

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();
Copy link
Contributor

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

@ktf
Copy link
Contributor Author

ktf commented Sep 26, 2013

I initially had two locks, but that was clearly useless... I cleaned it up...

@cmsbuild
Copy link
Contributor

Pull request #924 was updated. @smuzaffar, @Dr15Jones, @ktf, @nclopezo can you please check and sign again.

@Dr15Jones
Copy link
Contributor

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?

@ktf
Copy link
Contributor Author

ktf commented Sep 26, 2013

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.

@Dr15Jones
Copy link
Contributor

+1

@cmsbuild
Copy link
Contributor

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?

@cmsbuild
Copy link
Contributor

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?

@ktf
Copy link
Contributor Author

ktf commented Sep 27, 2013

Merging this since we all agree. I'll fix all the related bit in a separate pull request.

ktf added a commit that referenced this pull request Sep 27, 2013
Thread safety -- Thread safe Xerces-C setup / termination.
@ktf ktf merged commit 007f438 into cms-sw:CMSSW_7_0_X Sep 27, 2013
@ktf ktf deleted the thread-safe-xerces-c branch September 27, 2013 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants