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:
  1. R2012a 64bit, Win7
  2. put a break-point in the subfunction, index_out_of_bounds, at line 7
  3. start the function, spurious_fire_from_timer
  4. at the break-point execute stk1 = dbstack;
  5. open an m-file in the editor
  6. at the break-point execute stk2 = dbstack;
  7. inspect the stack-drop-down-list
  8. run whos and {stk2.name}'
  9. click [Continue] (/F5)
  10. 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
Tom Shlomo 2019 年 2 月 5 日
I experience the same problem with MATLAB 2018b, WIN10
Any chance you managed to solve this?
per isakson
per isakson 2019 年 2 月 22 日
No, I'm afraid not.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeBackground and Parallel Processing についてさらに検索

質問済み:

2013 年 3 月 6 日

コメント済み:

2019 年 2 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by