Spurious fire from timer
显示 更早的评论
Question: Has anyone experienced the behavior, which I describe here?
Posting questions here makes me think. This is a better version of Weird behavior when debugging code invoked by timer.
I argue that it happens that a callback is spuriously fired during debugging of code invoked by a timer. Now, I think I have a way to demonstrate the behavior; that is to reproduce the behavior.
Recipe:
- R2012a 64bit, Win7
- put a break-point in the subfunction, index_out_of_bounds, at line 7
- start the function, spurious_fire_from_timer
- at the break-point execute stk1 = dbstack;
- open an m-file in the editor
- at the break-point execute stk2 = dbstack;
- inspect the stack-drop-down-list
- run whos and {stk2.name}'
- click [Continue] (/F5)
- run whos and {stk1.name}'
K>> whos
Name Size Bytes Class Attributes
a 1x1 8 double
stk2 10x1 4164 struct
Note that stk1 is not in this workspace and display the function names
K>> {stk2.name}'
ans =
'index_out_of_bounds'
'invoked_by_timer'
'timercb'
'timercb'
'index_out_of_bounds'
'invoked_by_timer'
'timercb'
'timercb'
'wait'
'spurious_fire_from_timer'
[Continue] shows
Error while evaluating TimerFcn for timer 'my_timer'
Index exceeds matrix dimensions.
and takes us back to the first break. Now, stk1 is in the current workspace
K>> whos
Name Size Bytes Class Attributes
a 1x1 8 double
stk1 6x1 2582 struct
K>> {stk1.name}'
ans =
'index_out_of_bounds'
'invoked_by_timer'
'timercb'
'timercb'
'wait'
'spurious_fire_from_timer'
K>>
Comments:
- This shows that opening an m-file caused Matlab to fire a callback.
- I think this can be triggered by other user actions as well. However, I'm not sure which or whether it is intermittent.
- While experimenting with this behavior yesterday Matlab once crashed "without smoke"; just dropped dead without any crash report.
- This behavior does not occur (i.e. I failed to make it happen) with 'ExecutionMode' equal to 'singleShot'
where
function spurious_fire_from_timer()
tmr = timer('Name' , 'my_timer' ...
, 'TimerFcn' , @invoked_by_timer ...
, 'BusyMode' , 'drop' ...
, 'ExecutionMode' , 'fixedRate' ...
, 'Period' , 1 ...
, 'StartDelay' , 1 ...
, 'TasksToExecute', 1 ...
);
start( tmr )
wait ( tmr )
end
and
function invoked_by_timer( tmr, evnt )
index_out_of_bounds()
variable_not_used( tmr, evnt )
end
function index_out_of_bounds()
a = 17;
b = 18;
c = a(2);
variable_not_used( a, b, c )
end
and
function variable_not_used( varargin )
% variable_not_used - helps keep the code analyzer box green
end
2 个评论
Tom Shlomo
2019-2-5
I experience the same problem with MATLAB 2018b, WIN10
Any chance you managed to solve this?
per isakson
2019-2-22
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Background and Parallel Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!