siddhi
siddhi copied to clipboard
Fix improper activeThreads increments (issue 1842)
Purpose
Resolves issue 1842 - Improper threads synchronization in the ThreadBarrier leading to snapshot failures.
Goals
Fix the logic of the ThreadBarrier class to not increment activeThreads counter when threadBarrier.enter() is called in the same thread for which the counter has already been incremented. Used ThreadLocal to maintain counter of enter method invocations within the current thread. Used custom wrapper class MutualInteger for it as it's 5-6x faster than use of threadLocal's get() and set():
ThreadLocalBenchmark.testAtomicInteger 838.083 us/op ThreadLocalBenchmark.testGetAndSet 3431.792 us/op ThreadLocalBenchmark.testMutableInteger 558.584 us/op
Security checks
- Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes
- Ran FindSecurityBugs plugin and verified report? yes
- Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes