anchor.diff:  
   == The Need for External Languages
   
  -The main limitation when trying to use MATLAB to interface with hardware is that its scripting language is fundamentally single threaded. It has been designed to allow non-programmers to do complex math operations without needing to worry about programming concepts like multi-threading or synchronization.
  +The main limitation when trying to use MATLAB to interface with hardware stems from the fact that its scripting language is fundamentally single threaded. It has been designed to allow non-programmers to do complex math operations without needing to worry about programming concepts like multi-threading or synchronization.
   
   This poses a problem for real-time control of hardware because all communication is forced to happen synchronously in the main thread. For example, if a control loop runs at 100Hz and it takes a message ~8ms for a round-trip, the main thread ends up wasting 80% of the available time budget waiting for a response without doing any actual work.
   
  
positive.code: .Communications overhead in the main MATLAB thread
  image::matlab/comms-single-threaded.png[link="{imagesdir}/matlab/comms-single-threaded.png", width="100%"]
  
  Pure MATLAB implementations can work for simple applications, such as interfacing with an Arduino to gather temperature data or blink an LED, but it is not feasible control complex robotic systems at high rates. Fortunately, MATLAB does have the ability to interface with other programming languages that allow users to create background threads that can offload the communications aspect from the main thread. This frees MATLAB to focus on the calculations that it has been optimized for.
  
  [.text-center]
  .Communications overhead offloaded to other threads
  
negative.code:         }
      }
  
      /**
       * Method that gets called from MATLAB to receive new messages
       */
      public synchronized Message getNextMessage(long timeout_ms) {
      
  		if (!messages.isEmpty()) {
  		    return messages.removeFirst();
          }
  
          if (timeout_ms == 0) { // non-blocking
              return null;
          }
          
          // Wait for new message until timeout ...
      }
      
  }
  ----
  
  Note that the _getNextMessage_ method expects a user settable timeout argument. In general it is important for blocking Java methods to have a timeout in order to prevent the main thread from getting stuck permanently. Being in a Java call prohibits users from aborting the execution (ctrl-c), so timeouts should be reasonably short, i.e., in the low seconds. Otherwise this could cause the UI to become unresponsive and users may be forced to close MATLAB without being able to save their workspace.
  
  Passing in a timeout of zero serves as a non-blocking interface that immediately returns empty if no messages are available. This is often useful for working with multiple aggregators or for integrating asynchronous messages with unknown timing, such as user input.
  
  