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.
Describe the changes
I believe, there was a memory order bug, concerning usage of atomic flags before condition_variable.notify.
According to https://en.cppreference.com/w/cpp/thread/condition_variable
So I fenced both flags and notify statement with mutex.
Testing
Have you tested the new code using the provided automated test program and/or performed any other tests to ensure that it works correctly? If so, please provide information about the test system(s):
Yes, I did.
Additional information
When I used Your project as a template for my personal project, I had a bug where threads would be notified before end flag set to true causing deadlock. It was captured using high-end system and I could not replicate it on my personal computer.