From 45b766a5dc0820f7fb6ff7d940f1fd322f8844e7 Mon Sep 17 00:00:00 2001 From: Thad House Date: Mon, 7 Oct 2019 20:45:33 -0700 Subject: [PATCH] Fix main thread ID being potentially incorrect for simulation (#1923) --- .../src/main/java/edu/wpi/first/wpilibj/RobotBase.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index c541f9a578..b40e1b862e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -38,7 +38,7 @@ public abstract class RobotBase implements AutoCloseable { * The ID of the main Java thread. */ // This is usually 1, but it is best to make sure - public static final long MAIN_THREAD_ID = Thread.currentThread().getId(); + private static long m_threadId = -1; private static void setupCameraServerShared() { CameraServerShared shared = new CameraServerShared() { @@ -65,7 +65,7 @@ public abstract class RobotBase implements AutoCloseable { @Override public Long getRobotMainThreadId() { - return MAIN_THREAD_ID; + return RobotBase.getMainThreadId(); } @Override @@ -90,6 +90,7 @@ public abstract class RobotBase implements AutoCloseable { */ protected RobotBase() { NetworkTableInstance inst = NetworkTableInstance.getDefault(); + m_threadId = Thread.currentThread().getId(); setupCameraServerShared(); inst.setNetworkIdentity("Robot"); inst.startServer("/home/lvuser/networktables.ini"); @@ -100,6 +101,10 @@ public abstract class RobotBase implements AutoCloseable { Shuffleboard.disableActuatorWidgets(); } + public static long getMainThreadId() { + return m_threadId; + } + @Deprecated public void free() { }