When using MATLAB through the GUI, I can easily interrupt a computation by pressing Ctrl-C.
Is there a way to do the same programmatically when using MATLAB through the MATLAB Engine C API?
On Unix systems there is a solution: send a SIGINT signal. This will not kill MATLAB. It'll only interrupt the computation (i.e. exactly what I want). I am looking for a solution that works on Windows.
Use case: this is for a Mathematica-MATLAB interface. I want to be able to forward interrupts from Mathematica to MATLAB. The functionality is working and implemented on Linux/OSX, but I'd prefer to have it for the majority Windows platform as well.
EDIT: I'm also interested in solution that work with the MEX interface. The MEX function would be multi-threaded where the first thread is running an evalc(), and the second is watching for interrupt conditions. How would the second thread interrupt the evalc()? I have less hope for this with MEX than with Engine though.
UPDATE: I still haven't found any way to do this with the Engine interface, but I did find something which might work with MEX. The libut library has a function called utSetInterruptPending(). When running sequentially, utSetInterruptPending(1) will interrupt MATLAB (as tested with calllib()). Does anyone know utSetInterruptPending() is safe to call in a MEX function from a different thread than the main one?
MS Windows XP SP2 and later support POSIX signals including (presumably) SIG_INT.
Play games and win prizes!Learn more