December 12, 2015
A race condition happens when the outcome of the program depends on the sequence or timing of other uncontrollable events. It becomes a bug when events do not happen in the order the programmer intendedWe searched inside eclipse for race conditions to see what are the most common types of race conditions inside eclipse and its plugins.
The following types of race conditions were found by vmlens inside eclipse luna during startup and debugging of a java project:
Object | Count |
---|---|
Concurrently Accessed Fields | 2065 |
Fields Traced | 27114 |
Monitors | 7162 |
Locks | 427 |
Threads | 52 |
Volatile Fields | 2836 |
2836 volatile fields were used. For 3 more fields it would have been necessary to declare them as volatile. This leads to the second type of race conditions found, visibility problems.
The jvm does not directly write field updates into the main memory but first in registers or a cache of your cpu. As long as your program is running on one core of your pc, this is not a problem. But if the threads runs on different cores, they probably will not see the updates to the fields.
This problem appears most often with boolean flags. Like the terminated field of org.eclipse.equinox.internal.util.impl.tpt.timer.TimerImpl in the run method:
public void run() { TimerQueueNode n = null; while (!terminated) { synchronized (sync) { if (n == null && queue.isEmpty()) { try { sync.wait(); } catch (Exception e) { } // todo check if isEmpty is necessary if (queue.isEmpty() || terminated) { continue; } } }
© 2020 vmlens Legal Notice Privacy Policy