#pragma once

#include <chrono>
#include <functional>
#include <thread>
#include <atomic>

using Clock = std::chrono::steady_clock;

class Tick
{
public:
    Tick(std::chrono::microseconds timeBetweenTicks,
         std::function<void()>&& onTick)
        : timeBetweenTicks_(timeBetweenTicks)
        , onTick_(std::move(onTick))
        , active_(true)
        , timerThread_([this] { Loop(); }) // note initialization order is very important here; 
                                            // thread should start last
    {}

    void Deactivate() { active_ = false; timerThread_.join(); }

private:
    void Loop() const
    {
        while (active_)
        {
            for (auto start = Clock::now(), now = start;
                 now < start + timeBetweenTicks_;
                 now = Clock::now()) { /* Until next tick */
            }
            onTick_();	// may take significant time!
        }
    }

    const std::function<void()> onTick_;
    const std::chrono::microseconds timeBetweenTicks_;
    std::atomic<bool> active_;
    std::thread timerThread_;
};

#pragma once

#include <chrono>
#include <functional>
#include <thread>
#include <atomic>

class Tick
{
public:
    Tick(std::chrono::microseconds timeBetweenTicks,
         std::function<void()>&& onTick)
        : timeBetweenTicks_(timeBetweenTicks)
        , onTick_(std::move(onTick))
        , active_(true)
        , timerThread_([this] { Loop(); }) // note initialization order is very important here; 
                                            // thread should start last
    {}

    void Deactivate() { active_ = false; timerThread_.join(); }

private:
    void Loop() const
    {
        while (active_)
        {
            for (auto start = std::chrono::steady_clock::now(), now = start;
                 now < start + timeBetweenTicks_;
                 now = std::chrono::high_resolution_clock::now()) { /* Until next tick */
            }
            onTick_();	// may take significant time!
        }
    }

    const std::function<void()> onTick_;
    const std::chrono::microseconds timeBetweenTicks_;
    std::atomic<bool> active_;
    std::thread timerThread_;
};

--- 
+++ 
@@ -4,6 +4,8 @@
 #include <functional>
 #include <thread>
 #include <atomic>
+
+using Clock = std::chrono::steady_clock;
 
 class Tick
 {
@@ -24,9 +26,9 @@
     {
         while (active_)
         {
-            for (auto start = std::chrono::steady_clock::now(), now = start;
+            for (auto start = Clock::now(), now = start;
                  now < start + timeBetweenTicks_;
-                 now = std::chrono::high_resolution_clock::now()) { /* Until next tick */
+                 now = Clock::now()) { /* Until next tick */
             }
             onTick_();	// may take significant time!
         }
Fix incorrect usage of 2 different clocks to a single uniform clock
