-
Notifications
You must be signed in to change notification settings - Fork 633
improve thread safety for concurrent tiff loads #3767
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
improve thread safety for concurrent tiff loads #3767
Conversation
…thread-safety-for-concurrent-tiff-loads
src/libOpenImageIO/icc.cpp
Outdated
// return color_space_names[color_space]; | ||
auto it = color_space_names.find(color_space); | ||
return (it != color_space_names.end()) ? it->second : nullptr; | ||
|
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.
Can you get rid of the extra blank line here, please?
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 removed the blank line.
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.
Wow, good catch. It did not occur to me that it might be queried with a key that wasn't already in the map, thus potentially altering it and breaking thread safety. I should have declared these const all along.
The whole thing LGTM except for the syntax error I pointed out with the missing brace.
053453e
to
adc9705
Compare
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.
LGTM, thanks!
…ation#3767) * Make lookups of const unordered_maps thread-safe * added back deleted end brace * clang-format --------- Co-authored-by: Larry Gritz <[email protected]>
…ation#3767) * Make lookups of const unordered_maps thread-safe * added back deleted end brace * clang-format --------- Co-authored-by: Larry Gritz <[email protected]>
Description
This fixes a thread-safety issue with concurrent parsing of multiple tiff files. The code uses several static std::unordered_maps and the indexing operator[] was used to perform the lookup. Use of this operator has the side effect of adding a default value to the map if the key was not found. This is not what should happen and isn't thread safe. The proper fix is to make the maps const and use the find() method of the map to perform the lookup and return a default value if not found.
Tests
Tests were not performed. However the code changes were tested within the context of loading USD files with multiple tiff files.
Checklist:
have previously submitted a Contributor License Agreement
(individual, and if there is any way my
employers might think my programming belongs to them, then also
corporate).
(adding new test cases if necessary).