Created
May 19, 2015 07:29
-
-
Save swkwon/4760bcf79c3b2468d4d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <thread> | |
#include <future> | |
#include <iostream> | |
class SuspendThread { | |
private: | |
std::function<void()> func; | |
std::thread task; | |
public: | |
template<typename FN_, typename ... Arguments> | |
SuspendThread(FN_ func, Arguments&& ... args) | |
: func(std::bind(func, std::forward<Arguments>(args)...)) | |
{ | |
} | |
~SuspendThread() | |
{ | |
task.join(); | |
} | |
void run() | |
{ | |
std::thread t(func); | |
task = std::move(t); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment