-
Notifications
You must be signed in to change notification settings - Fork 147
Few WorkManager fields are not MT safe #2149
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
base: master
Are you sure you want to change the base?
Few WorkManager fields are not MT safe #2149
Conversation
Few fields are not volatile/atomic but could be accessed from different threads, so even if the modification happens while holding workspace locks, other threads might see stale values. Fields in question are - `WorkManager.operationCanceled` - `WorkManager.nestedOperations` - `WorkManager.preparedOperations` Additionally changed Workspace.endOperation() to read workManager.getPreparedOperationDepth() only once to avoid inconsistent reads. Fixes eclipse-platform#2148
Wo other threads are reading the values outside the workspace lock? Looking at the code changes it seem not to really benefit / improve from the changes otherwise, e.g. the atomic operation is never used to compareAndSet and otherwise only unconditional set values. |
I'm not saying that they are reading outside the lock, I'm saying they are probably reading stale values. |
If they are reading them under the workspace look, how can they ever see stale values?
I always wondered where the impression comes from that only synchronized methods are barriers and anyone should see "stale" data, if that would be the case we would need synchronized everywhere and java would be completely unusable as a programming language. |
I never said that, please carefully quote what I've said.
The workspace lock I mean is Given that, quote myself, note the "might" verb:
Therefore IMO if we know the code is runing in multiple threads, the fields are not volatile, and we can't easily proof all paths that read/write of the fields are properly guarded by either synchronized blocks or the lock above, it is safer to make the code protected from possible MT issues. |
But that's the point, if we can't prove that then the change does not gives us anything better regards MT issues, it would only solve e.g. if we can see that one code hangs forever (e.g. boolean value is not visible due to missing volatile as its cached) but as you said you can't give a proof here. Second is the update of the filed, now made atomic but still do not prevent from a race condition (that is one Thread is writing a value where another is seeing a stale value and behave wrong). So I'm really a bit reserved on changing code based on "feelings" ( = might help but might not and we hope it does not harm) instead of at least facts (what would be for example a callstack that shows problematic access or at least a description of the case to fix). You are referencing explicitly an issue in JDT, so how/why would one even expect to make the situation better there with this change? |
Few fields are not volatile/atomic but could be accessed from different threads, so even if the modification happens while holding workspace locks, other threads might see stale values.
Fields in question are
WorkManager.operationCanceled
WorkManager.nestedOperations
WorkManager.preparedOperations
Additionally changed Workspace.endOperation() to read workManager.getPreparedOperationDepth() only once to avoid inconsistent reads.
Fixes #2148