Timers: possible bug/documentation error

1 visualización (últimos 30 días)
Daniel Shub
Daniel Shub el 10 de Mzo. de 2013
A few years ago I asked this question about timers. I took Walter's answer as gospel and didn't bother testing it since the potential for timers to operate in a different thread made them unsuitable for my application. Per has a recent question on timers where the problem has come up again.
At the root of the problem is that the documentation says
But in the case of a block of code:
y=x(1:500000);
y=[y x(500001:1000000)];
a timer shot can occur after the first statement and change "x".
But if I run (note you may have to adjust the number of iterations to give a reasonable run time)
function test
h = timer('TimerFcn', @(src, evt)toc, 'ExecutionMode', 'FixedRate');
tic; start(h);
pause(2);
for ii = 1:5e2
x = randn(1000000, 1);
y = x(1:500000);
y = [y x(500001:1000000)];
end
pause(2);
stop(h);
delete(h);
end
I get
Elapsed time is 0.001405 seconds.
Elapsed time is 1.001806 seconds.
Elapsed time is 2.002036 seconds.
Elapsed time is 16.791777 seconds.
Elapsed time is 17.001169 seconds.
Elapsed time is 18.001609 seconds.
The timer appears to fire immediately after starting (as you would expect), and twice more during the pause before the loop starts (again as expected). There is then a 14.8 second gap (about the amount of time the loop takes in the absence of the timer) followed by 3 more timer events (again expected given the 2 second pause).
What am I missing? I am using R2011a, did something change in the 16 months following the release of the tech report. Is there new documentation.

Respuestas (1)

per isakson
per isakson el 10 de Mzo. de 2013
Editada: per isakson el 10 de Mzo. de 2013
I reproduced your result with R2012a 64Bit, Win7. However, with the accelerator turned off the timer interupt the for-loop as described in the tech-note.
>> feature('accel','off')
>> synchronization_1_2QJ375
Elapsed time is 0.001245 seconds.
Elapsed time is 0.995859 seconds.
Elapsed time is 1.995819 seconds.
Elapsed time is 2.999274 seconds.
Elapsed time is 3.998288 seconds.
Elapsed time is 5.014897 seconds.
Elapsed time is 6.030949 seconds.
Elapsed time is 7.008298 seconds.
Elapsed time is 8.004866 seconds.
...
The function, feature, is documented over at Undocumented Matlab
  2 comentarios
Daniel Shub
Daniel Shub el 11 de Mzo. de 2013
Editada: Daniel Shub el 11 de Mzo. de 2013
I missed the fact that the documentation says the JIT can combine several lines of code. So basically there is no way to know if a timer can interrupt between two particular lines of code. Why in the world they don't just stick timer callbacks into the event queue is beyond me.
Jan
Jan el 11 de Mzo. de 2013
@Daniel: We need two kind of timers, one with a queue e.g. triggered by darwnow as usual, and one, which can be expected to fire independently, which can cause serious crashs. Well, let's forget the crashing variant, because it is easy to implement it in a Mex. How could the JIT accelerate code, when a TIMER can inject values?!

Iniciar sesión para comentar.

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by