Problem restarting HiResTimer?


I am running on the Mac for the Mac platform using a HighResolutionTimer-derived class.

It seems that the startTimer(int) routine is ignored or does not work when I re-launch it from the hiResTimerCallback method (to merely change the callback delay). It keeps the same delay used to launch the callback the first time.

<EDIT> After more testing, the problem seems more complex than just ignoring the subsequent startTimer calls...</EDIT>

<EDIT2> Just realized that I was in Android forum. I'll make a copy in the General forum as I am assuming the same problem will occur in all platforms</EDIT2>

class myTimer : HighResolutionTimer {
    myTimer() {};
    ~myTimer() {};   

    void startIt()
        startTimer(100);    // This delay (100) seems to be used forever ?

    void hiResTimerCallback() override
            startTimer(1000);    // Seems to be ignored

The same code works fine if I use a regular Timer class.

Can you please confirm or am I doing something wrong ?



I'm not on a Mac at the moment, so I can't verify in a debugger, but in looking at the code, it looks like you could end up with two timers running in the situation where you call start from the callback. ie. the ::start routine calls ::stop, which sets shouldStop to true, but ::stop exits without waiting for the thread to end, while (... && thread != pthread_self()), and once it returns to ::start shouldStop is set to false again, leaving the original thread running, and then the new timer thread is created (overwriting the handle to the original thread).