Changed bool running into a std::atomic<bool> to avoid possible race conditions
bool running
std::atomic<bool>