Timer precedence during called functions
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (3개)
Walter Roberson
2012년 4월 3일
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
Daniel Shub
2012년 4월 4일
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.
Jan
2012년 4월 4일
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
Daniel Shub
2012년 4월 4일
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.
Sean de Wolski
2012년 4월 3일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!