Timer precedence during called functions

2 views (last 30 days)
Sean
Sean on 3 Apr 2012
Hello,
I have a timer that is pulling in video frames as a preview in a GUI. Unfortunately, I have found that if I call other functions, the timer waits until the function fully completes before executing. By this I mean that if I run a module to analyze the incoming video, the preview stops working until the analysis is completed.
Does anyone know how I can give the timer function precedence, so that it can perform its frame acquisition in between lines of called functions instead of waiting until they complete?
Thanks in advance, Sean

Answers (3)

Walter Roberson
Walter Roberson on 3 Apr 2012
Which MATLAB version are you using? There was a major change in timer precedence somewhere around R2006b-ish .
But as Sean points out, timers cannot interrupt built-in functions. These days they can, however, interrupt regular .m functions, even callbacks.
  3 Comments
Walter Roberson
Walter Roberson on 4 Apr 2012
Good point, I should have said, "even handle graphic callbacks"
Daniel Shub
Daniel Shub on 4 Apr 2012
Callbacks are now wider than timers and graphics: handle objects, serial port objects, and audioplayer objects can all have callbacks. I think all callbacks except timers behave the same and operate out of the same thread.

Sign in to comment.


Jan
Jan on 4 Apr 2012
Walter, Sean, Daniel: We need an exhaustive documentation of the timer precedence and the multi-threading effects e.g. concerning global 's in a timer callback. There must be a documentation anywhere already. It is time to publish it.
A bunch of drawnows is messy. How can we check the length of the event queue programmatically?
  1 Comment
Daniel Shub
Daniel Shub on 4 Apr 2012
Yes we do. I use globals so infrequently, I don't even know how they work in standard callbacks.
As for the event queue, I think this should be a new question. I could see lots of uses for this. Even better if you could manipulate the queue. A couple of years ago Yair posted this: http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/ which could be the start.

Sign in to comment.


Sean de Wolski
Sean de Wolski on 3 Apr 2012
Set the timer's 'busymode' option to 'queue' so that the most recent event is queued. Then add a bunch of drawnows in your code to flush the queue while your code is running.
doc drawnow
This still will not interrupt functions such as mtimes or fft that don't check the queue (the same reason you can't ctrl+c out of it) but it will flush the timer events if its your own code blocking the timer.

Categories

Find more on Startup and Shutdown 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!