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

Synchronizer: concurrency fixes #147

Closed
wants to merge 2 commits into from

Conversation

champtar
Copy link
Contributor

Except if you use Atomic* or volatile, you have to lock/synchronize for both writing and reading.

HashMap are not thread safe, even when reading,
so we can't use them outside of synchronized blocks,
else we can have some random crash or data/result
inconsistencies between threads.

ConcurrentHashMap is a well optimised beast, so use it.

Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
If you synchronize for writing you have to synchronize
for reading too.

Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
@ibauersachs
Copy link
Member

ibauersachs commented May 12, 2016

The first commit is fine. In the second one, the unsynchronized that were there before reads are okay because the conditions are checked again after obtaining a lock. The valid changes in the second commit are thus only the parameter validations.

@champtar
Copy link
Contributor Author

This type of check is only ok if you have an initial state (set in the constructor) and you never go back to it, and that's not the case here (see removeMapping).
synchronised ensure atomicity but also visibility between threads

@ibauersachs
Copy link
Member

@bgrozev informed me that this code isn't even in use. As I'm lacking time to go through it again, I'm closing this PR.

@champtar
Copy link
Contributor Author

@ibauersachs this was spotted with FindBugs and haven't checked that it's used

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.

None yet

2 participants