Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimeon Andreev2020-11-24 15:41:37 +0000
committerJonah Graham2020-11-29 19:41:34 +0000
commit7881736c68b43b152e12e8efa2fc67f046046179 (patch)
tree39812757214e1394b45e3d69125a5f78f50e306e /dsf-gdb
parent293998da18c4c15613b9a6880c351e5ce1cb6c71 (diff)
downloadorg.eclipse.cdt-7881736c68b43b152e12e8efa2fc67f046046179.tar.gz
org.eclipse.cdt-7881736c68b43b152e12e8efa2fc67f046046179.tar.xz
org.eclipse.cdt-7881736c68b43b152e12e8efa2fc67f046046179.zip
Bug 569123 - Race condition on AbstractMIControl.fRxCommands
This change adds synchronization to iterating over the map AbstractMIControl.fRxCommands during AbstractMIControl.cancelRxCommands(). This prevents potential ConcurrentModificationExceptions when elements are added or removed to the map in parallel during e.g. AbstractMIControl.TxThread.run() loop. The change also removes superfluous synchronization for method AbstractMIControl.cancelRxCommands(). Change-Id: Id7c01b3057e522cce324a002dce54f0fabe02623 Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Diffstat (limited to 'dsf-gdb')
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
index 4908a50a763..8db4f3b9bf3 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -327,14 +328,18 @@ public abstract class AbstractMIControl extends AbstractDsfService implements IM
fTxCommands.add(fTerminatorHandle);
}
- private synchronized void cancelRxCommands() {
- for (CommandHandle commandHandle : fRxCommands.values()) {
+ private void cancelRxCommands() {
+ Map<Integer, CommandHandle> rxCommandsCopy;
+ synchronized (fRxCommands) {
+ rxCommandsCopy = new LinkedHashMap<>(fRxCommands);
+ fRxCommands.clear();
+ }
+ for (CommandHandle commandHandle : rxCommandsCopy.values()) {
if (commandHandle.getRequestMonitor() == null)
continue;
commandHandle.getRequestMonitor().setStatus(genStatus("Connection is shut down")); //$NON-NLS-1$
commandHandle.getRequestMonitor().done();
}
- fRxCommands.clear();
}
/**

Back to the top