Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XML library initialisation is not thread safe (#272)
Note that calling XMLPlatformUtils::Initialize is currently not thread safe Co-authored-by: Nigel Stewart <nigel.stewart@emesent.io>
- Loading branch information
4fba305
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.
Hi @nigels-com
could the function : void E57XmlParser::init() be static ?
so we could
E57XmlParser::init();
multithreaded reading access functions here in loop
E57XmlParser::destroy()
4fba305
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.
One option here is C++11 call_once wrapped around the
XMLPlatformUtils::Initialize
call.But that doesn't take care of cleaning up with
XMLPlatformUtils::Terminate
when all the readers are done.Perhaps a static C++11 mutex protected reference count?
Initialize
happens (while locked) for ++count == 1 andTerminate
(while locked) when --count == 0?4fba305
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.
i guess option one,why not let the user manually handle this ? actually from xerces FAQ:
The application also needs to guarantee that the XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() methods are called from the same thread (usually the initial thread executing main()) or proper synchronization is performed by the application if multiple threads call XMLPlatformUtils::Initialize() and XMLPlatformUtils::Terminate() concurrently.
4fba305
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.
The main downside is that it's a compatibility-breaking change.