Skip to content

Instantly share code, notes, and snippets.

@swkwon
Created May 19, 2015 07:29
Show Gist options
  • Save swkwon/4760bcf79c3b2468d4d6 to your computer and use it in GitHub Desktop.
Save swkwon/4760bcf79c3b2468d4d6 to your computer and use it in GitHub Desktop.
#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