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

2 views (last 30 days)
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.

Accepted Answer

Nolin Borrero Jr
Nolin Borrero Jr on 12 Aug 2021
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.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!