From 88df7cd314269fa1debe226b49b7e4e9dc238d8e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 24 Oct 2014 21:21:19 -0700 Subject: [PATCH 1/1] altoslib: synchronize access to serial debug output list This list is access by both the receiver and the monitor task, so it needs to be locked to prevent collisions. Signed-off-by: Keith Packard --- altoslib/AltosLink.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java index 62bd82b9..c0031cad 100644 --- a/altoslib/AltosLink.java +++ b/altoslib/AltosLink.java @@ -55,8 +55,11 @@ public abstract class AltosLink implements Runnable { public void printf(String format, Object ... arguments) { String line = String.format(format, arguments); - if (debug) - pending_output.add(line); + if (debug) { + synchronized (pending_output) { + pending_output.add(line); + } + } try { print(line); } catch (InterruptedException ie) { @@ -286,12 +289,14 @@ public abstract class AltosLink implements Runnable { binary_queue.put(dup); } - public void flush_output() { + public synchronized void flush_output() { if (pending_output == null) return; - for (String s : pending_output) - System.out.print(s); - pending_output.clear(); + synchronized (pending_output) { + for (String s : pending_output) + System.out.print(s); + pending_output.clear(); + } } public void flush_input(int timeout) throws InterruptedException { -- 2.30.2