Add C++ binding/implementation thread safety options#220
Merged
gangatp merged 15 commits intoAutodesk:developfrom Jun 27, 2025
Merged
Add C++ binding/implementation thread safety options#220gangatp merged 15 commits intoAutodesk:developfrom
gangatp merged 15 commits intoAutodesk:developfrom
Conversation
b1df7c1 to
53405b6
Compare
…ticComponentToolkit into uck/ThreadSafety
53405b6 to
cba7f69
Compare
…ticComponentToolkit into uck/ThreadSafety
gangatp
reviewed
Jun 16, 2025
gangatp
reviewed
Jun 16, 2025
| int main() | ||
| { | ||
| std::string libpath = (""); // TODO: put the location of the LibThreadSafe-library file here. | ||
| auto wrapper = LibThreadSafe::CWrapper::loadLibrary(libpath + ""); // TODO: add correct suffix of the library |
Collaborator
There was a problem hiding this comment.
library is not mentioned here.
gangatp
previously approved these changes
Jun 16, 2025
Collaborator
gangatp
left a comment
There was a problem hiding this comment.
looks good. thank you. left few comments.
gangatp
approved these changes
Jun 17, 2025
Collaborator
gangatp
left a comment
There was a problem hiding this comment.
I could build the example and run it. It creates the class instances. Thank you. I will add this to the build pipeline later.
This was referenced Jun 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This solution adds 2 new virtual methods IBase::_lockInstance and IBase::_UnlockInstance on the implementation side with empty implementation. It also adds new class IBaseWithMutex that derives from Ibase. Those methods are being injected to base class methods so they will be exposed through and API (as private). It all happens only if one (or more) class has ThreadSafetyOption attribute set to "strict" or "soft".
Difference between soft and strict:
soft - binding side will call _lockInstance only if string / array is returned from API function
strict - binding side will call _lockInstance everytime, no matter what is returned from function
IBaseWithMutex Definition:
When ThreadSafetyOption attribute in LibraryManager component class is set to "soft" or "strict", ILibraryManager will derive from IBaseWithMutex instead of Ibase
Example binding side functions created when ThreadSafetyOption is set to soft:
With this approach we are locking / unlocking mutex on implementation side so we can have X different instances of the Binding-Class pointing to the same Implementations-Class and all of this should work fine. On the binding side _lockInstance and _unlockInstance are private so one should use them by accident.
One more thing, CheckError will unlock hande in case of "exception propagation"
Just like with binding side, any changes on binding side will happen only when one (or more) class has ThreadSafetyOption attribute set to "strict" or "soft".