Last active
August 29, 2015 14:21
-
-
Save swkwon/b23ad4801464e0bfee26 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
class SuspendThread { | |
private: | |
std::thread task; | |
std::promise<void> Psuspend; | |
public: | |
template<typename FN_, typename ... Arguments> | |
SuspendThread(FN_ func, Arguments&& ... args) | |
{ | |
auto fut_suspend = Psuspend.get_future(); | |
std::thread it( | |
[func](std::future<void>&& fut, auto&&... args) | |
{ | |
fut.wait(); | |
func(std::forward<Arguments>(args)...); | |
}, std::move(fut_suspend), std::forward<Arguments>(args)...); | |
task.swap(it); | |
} | |
~SuspendThread() | |
{ | |
task.join(); | |
} | |
void run() noexcept | |
{ | |
Psuspend.set_value(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment