-
Notifications
You must be signed in to change notification settings - Fork 152
BATIK-1271 Make rehash function thread safe #66
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
Conversation
|
I think that's not enough. When another thread modifies the table while rehash() is running, rehash will see the updated values in the loop, seeing a mix of old and new values. This does not seem right. OldTable would need to be copied, not just share a reference to the original array, but this can not be done atomically. The patch fixes concurrent rehashes, but all other methods that modify the table will still mess up the data. I don't see how this can be solved without explicit synchronization. |
|
@xzel23 Would you synchronize the entire public synchronized Value put(char c, Value value) { ... } |
|
Caveat: I just stumbled over this because I use BATIK in some projects and follow commits to the repository. I have no deeper knowledge of this project's codebase, and I might have become a little rusty with Java 8, so I hope I didn't accidentally use any post Java 8 feature . These are just some observations from looking at the commit and the files through the GitHub Web interface. It's much worse than that. Looking at the code for this class, it is inherently not thread safe. Methods that need synchronization are at least:
Possible SolutionsI think there are to ways to make this threadsafe:
Suggestion
Some more things to consider
|
|
Other proposal using |
|
Closing this in favour of #67 |
https://issues.apache.org/jira/browse/BATIK-1271