Catch some cases where we end up spinning forever in the mex function (and hence have to kill matlab)
Refactor threadFailed to threadFinished
This now correctly writes data to a single connected AM_TARGET