MATLAB: How do running MATLAB files, GUI callbacks, and timer callbacks interoperate in MATLAB 7.3 (R2006b)

MATLAB

I am trying to create a MATLAB application which behaves as a multithreaded application. With the use of a GUI and timers it seems like this is possible.

Best Answer

MATLAB has a single main execution thread and all MATLAB code executes within that thread. Timers and GUI callback functions can execute preemptively while other code is running. This provides multithreaded-like behavior, however, all the MATLAB code is being executed in the single main thread.
In general, a MATLAB function or callback completes execution and then the next callback executes. Certain commands pause the currently executing MATLAB function and allow MATLAB to process callbacks and graphics events. These commands include DRAWNOW, KEYBOARD, INPUT, and PAUSE. Timer functions, however, execute between lines of a running MATLAB function. This can cause unexpected behavior in functions that are not reentrant safe. You should design your code to handle reentrancy and you should not depend on global variables that might change state during reentrancy.
For more details on DRAWNOW execute the command:
doc drawnow