Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Matlab, when does Ctrl+C does not work and why?

According to http://www.mathworks.com/help/matlab/matlab_env/stop-execution.html, Ctrl+C does not work well for stopping execution of files that run a long time, or that call built-ins or MEX-files that run a long time. Why is that? I'd like to know more about the underlying reasons then just a superficial description of what I may expect. Also, does the alternative Cmd+. and Ctrl+Break work better really? Why?

like image 636
qazwsx Avatar asked Apr 08 '26 21:04

qazwsx


1 Answers

I would guess that's because forcing a thread to terminate as you seem to suggest could leave your application in an invalid state, including not releasing native resources that are hold by your MEX files such as memory etc. (MEX files are mapped in the same memory space as MATLAB). Pure MATLAB code can be interrupted because in that case MATLAB has control over all the resources.

That said, it is possible for MEX files to be interrupted by typing CTRL+C (or other mechanisms) but they have to be designed specifically for that using these undocumented functions:

bool utSetInterruptEnabled(bool);
bool utIsInterruptPending(void);
like image 158
gregswiss Avatar answered Apr 10 '26 23:04

gregswiss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!