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

fix DefaultMessageFactory thread-race issue #865

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

gbirchmeier
Copy link
Member

When multiple threads race to init DefaultMessageFactory, fix it so that later threads do not return before the first thread finishes loading all the dlls.

resolves #864

attn @baffled

When multiple threads race to init
DefaultMessageFactory, fix it so that later
threads do not return before the first thread
finishes loading all the dlls
And restore/update the ctor that I deleted
in the previous commit but then changed
my mind about

var dlls = Directory.GetFiles(directory, "QuickFix.*.dll");
foreach (var path in dlls)
_dllsAreLoaded = true;
Copy link
Contributor

@Rob-Hague Rob-Hague Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for ultimate thread safety, either _dllsAreLoaded needs to be marked with volatile or the first if before the lock needs to be removed (easiest to reason about). I think otherwise there is nothing theoretically preventing this write being executed out of order and becoming observable (by another thread outside the lock) before the preceding code has finished.

Pretty theoretical and I may be wrong as to whether that can actually happen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right that volatile is probably appropriate.

I was about to argue in favor of leaving the if in, but I realized that this function won't be called enough for that to cause any actual efficiency gain. Not sure why I didn't realize that when I wrote it.

@gbirchmeier
Copy link
Member Author

Oh, dang, I wish I'd gotten this into 1.12. I forgot that it was still open...

@gbirchmeier
Copy link
Member Author

Was hoping @baffled would take a look, but I guess he's not going to. Time to merge...

@gbirchmeier
Copy link
Member Author

@Rob-Hague I made the fix to remove the first "if". With that, the "volatile" modifier is probably not needed (which you kind of implied with your comment).

@Rob-Hague
Copy link
Contributor

Agreed, volatile not needed, looks good to me

@gbirchmeier gbirchmeier merged commit 6e127e6 into connamara:master Aug 27, 2024
2 checks passed
gbirchmeier added a commit to gbirchmeier/quickfixn that referenced this pull request Sep 12, 2024
It was planned to go into 1.12.0, but didn't make it
@gbirchmeier gbirchmeier deleted the i864-dll-race branch September 12, 2024 22:21
gbirchmeier added a commit that referenced this pull request Sep 13, 2024
hlibman-connamara pushed a commit to hlibman-connamara/quickfixn that referenced this pull request Dec 6, 2024
hlibman-connamara pushed a commit to hlibman-connamara/quickfixn that referenced this pull request Dec 6, 2024
fix DefaultMessageFactory thread-race issue
hlibman-connamara pushed a commit to hlibman-connamara/quickfixn that referenced this pull request Dec 6, 2024
It was planned to go into 1.12.0, but didn't make it
hlibman-connamara pushed a commit to hlibman-connamara/quickfixn that referenced this pull request Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timing issue loading DLLs
2 participants