// // Created by philipp on 05.02.18. // #ifndef PC2CAR_NOTIFIABLETHREAD_H #define PC2CAR_NOTIFIABLETHREAD_H #include <mutex> #include <thread> #include <atomic> #include <condition_variable> class NotifiableThread { public: using Callback = std::function<void()>; explicit NotifiableThread(const Callback & callback); ~NotifiableThread(); void notify(); private: std::thread runner; std::atomic<bool> running{true}; std::atomic<bool> notified{false}; std::mutex mutex; std::condition_variable notifiedCondition; Callback callback; void run(); }; #endif //PC2CAR_NOTIFIABLETHREAD_H