9 years, 6 months ago.

What happens if I call timer.start() and then timer.start() again?

What happens if I call timer.start() and then timer.start() again before reading the time? Does start the timer again from 0 or does nothing happen?

Question relating to:

As I am not able to post an answer (error), I'll copy it here:

Hi,

the implementation of timer's start method:

void Timer::start() {
    _start = us_ticker_read();
    _running = 1;
}

It sets start variable to the current time and running to 1.

Regards,
0xc0170

posted by Martin Kojtal 10 Oct 2014

2 Answers

9 years, 6 months ago.

FYI in latest mbed update the behavior has been changed (fixed): Now the second time you call timer.start() while the timer is already running will not do anything. mbed-src now has this behavior, the regular mbed lib will get it at the next update.

Why? It seems not very usefull this new behaviour. Pressing two times the start button of a regular chronometer will produce a new time-lapse measurement.

posted by Sistemes Encastats i Ubics FIB 02 Dec 2014

One difference is that a regular chronometer actually exposes something like lap-times, the Timer only uses something which could be compared internally.

I could see that there could be situations where you want to reset the current 'lap', but if that is wanted that function needs to be added: Start() should start the timer, not reset it partially imo.

posted by Erik - 02 Dec 2014
9 years, 1 month ago.

how about an extension like start(bool reset=false); I use the same timer for runtime measurements and always have to call t.reset(); before t.start();