Event Handling
15 views (last 30 days)
Show older comments
My program is setup so that it can be interupted by a number of external events. These events happen randomly and I can not predict where or when the interuption will occur. The interupting events run bits of code which change state variables in my program. Once the interuption has been processed and I have returned to my regular program code, is there any way for me to know I have been interupted? I would like the code which was running before the interuption to somehow know it was interupted and that maybe it should terminate and try running again from the beginning... if it doesnt it may continue with incorrect state information and make mistakes.
0 Comments
Answers (4)
Daniel Shub
on 12 Jan 2012
If you are not using timer objects, then your code will only be interrupted at well defined times, like when drawnow is called. For a complete list see http://www.mathworks.com/help/releases/R2011a/techdoc/ref/drawnow.html. If you code never flushes the event queue, then you know the state is okay.
Timer objects, however, throw this whole model out the window and exist in some separate thread that I don't think you can easily deal with: http://www.mathworks.com/matlabcentral/answers/22180-timers-and-thread-safety
You might be able to get all the timer objects at the beginning, get their execution counts, load your state data, do your processing, and then check the counts again.
0 Comments
Harry MacKenzie
on 12 Jan 2012
2 Comments
Daniel Shub
on 12 Jan 2012
My understanding is that if your code does something that results in a notify call (or the user initiates a callback), the event will be added to the event queue, but not processed until the event queue is flushed. The only exception that I am aware of is if the event arises from a timer object.
Walter Roberson
on 12 Jan 2012
The techniques are pretty much the same as for http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
0 Comments
Daniel Shub
on 12 Jan 2012
Now I got it. The source of the event is coming from a Java object. Yet another way around the single threaded MATLAB system.
1 Comment
Yair Altman
on 20 Jan 2012
I posted an article related to this yesterday: http://undocumentedmatlab.com/blog/matlab-java-memory-leaks-performance/ - it describes both Matlab callbacks of Java events, and its relationship to timer callbacks.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!