From fa8b68419f4c91da3e518f2ca71badceddf7b4d8 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 3 Mar 2016 23:37:45 -0800 Subject: [PATCH] Make Java AnalogGyro.getAngle() thread-safe. In the Java implementation, "result" is an instance variable (to avoid needing to perform a memory allocation on each call to getAngle). However, this means that calls to getAngle() from multiple threads can step on each other. Synchronize the method to avoid this issue. Reported by: Jackson Gray (http://www.chiefdelphi.com/forums/showthread.php?threadid=145124) Note this does not synchronize accesses between configuration methods such as calibrate() and accessor methods such as getAngle(). Change-Id: I9ecc962d4fba66f6134fd801cfd607f155b41fe5 --- wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogGyro.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogGyro.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogGyro.java index 9b1d8b5775..c2d541072d 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogGyro.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogGyro.java @@ -165,7 +165,7 @@ public class AnalogGyro extends GyroBase implements Gyro, PIDSource, LiveWindowS /** * {@inheritDoc} */ - public double getAngle() { + public synchronized double getAngle() { if (m_analog == null) { return 0.0; } else {