MCR - Pass variable during function processing to flag a cancellation request

조회 수: 2 (최근 30일)
I am using the 2017a runtime and trying to figure out how to pass a cancellation request.
When using the COM interface, I can put a pause in a function which seems to yield to pending requests and allows me to set a cancellation request flag. I do this using a global variable. Then, during those long running functions, it checks for that flag in different places.
When I try to run the same code using the MATLAB Runtime, the call to set the cancellation request flag doesn't make it through at the pause.
The code for checking for the flag looks like this:
function requested=cancel_requested()
global cancel_requested_flag;
pause(0.01);
requested = cancel_requested_flag;
cancel_requested_flag = false;
end
I call this function in various places to check for that flag. The code for setting the flag is below.
function request_cancel()
global cancel_requested_flag;
cancel_requested = true;
end
My cancel button just calls this request_cancel function. Again, this all works when using the COM interface. Any ideas how I can get this to work with the MATLAB Runtime? With the Runtime, it waits until the original function completes to call request_cancel. Pause doesn't seem to yield control the same way it does with the COM interface.

채택된 답변

Nolin Borrero Jr
Nolin Borrero Jr 2021년 8월 12일
In case anyone else runs into this issue, it doesn't look like it's possible to do what I was trying with the runtime.
The way I solved this issue of being able to cancel a long running function is by using a memmapfile and writing a 1 to the file whenever the user clicks "Cancel". Then in the "cancel_requested" function, it checks that byte to see if it's a 1 or a 0 and returns true or false.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by