Community
Participate
Working Groups
EclipsePreferences synchronizes on "this" which is a public object used by clients. If client code also synchronizes on that object via synchronized(preferenceNode) it could create a deadlock. The complete analysis of this problem is in bug 333726 comment 27.
Bug 333726 was critical and so is this one. The problem is not hypothetical. The deadlock does happen in CDT.
There are actually three problems here: 1) Use of a public object as the lock 2) Some accesses of the children field had no synchronization (internalChildNames) 3) None of the reads/writes on the properties field were synchronized. The data structure itself is thread safe, but lack of synchronization on field access/write could mean accessing stale values, or in the case of concurrent put(..) calls, it could result in lost preferences.
*** Bug 243893 has been marked as a duplicate of this bug. ***
http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=087d3b0910013b190998a81e3d49f2b99f7f1e34
(In reply to comment #4) > http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=087d3b0910013b190998a81e3d49f2b99f7f1e34 Hi John, while backporting your patch to 3.7.2 code I found one minor issue: shareStrings(StringPool pool) has an unsynchronized read of "properties" field value: public void shareStrings(StringPool pool) { properties.shareStrings(pool); Shouldn't be: public void shareStrings(StringPool pool) { synchronized (childAndPropertyLock) { properties.shareStrings(pool); } instead?
(In reply to comment #5) > Shouldn't be: > > public void shareStrings(StringPool pool) { > synchronized (childAndPropertyLock) { > properties.shareStrings(pool); > } > > instead? Or better: public void shareStrings(StringPool pool) { //thread safety: copy reference in case of concurrent change ImmutableMap temp; synchronized (childAndPropertyLock) { temp = properties; } temp.shareStrings(pool); ?
(In reply to comment #6) > > public void shareStrings(StringPool pool) { > //thread safety: copy reference in case of concurrent change > ImmutableMap temp; > synchronized (childAndPropertyLock) { > temp = properties; > } > temp.shareStrings(pool); > > ? I didn't bother with that one because it's just an optimization and having a stale value wouldn't cause any harm. But we might as well be consistent so I made this change: http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=52a7f6d48eacc72506ba42a6216246d2b4e441e8