38 lines
855 B
C++
38 lines
855 B
C++
#pragma once
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#elif __linux__
|
|
|
|
#else
|
|
#error "이 플랫폼은 지원되지 않습니다."
|
|
#endif
|
|
#include <functional>
|
|
|
|
namespace Chattr {
|
|
|
|
|
|
class Thread {
|
|
public:
|
|
#ifdef _WIN32
|
|
static DWORD WINAPI __thread(LPVOID param) {
|
|
std::unique_ptr<std::function<void()>> func(reinterpret_cast<std::function<void()>*>(param));
|
|
(*func)();
|
|
return 0;
|
|
}
|
|
#endif
|
|
template<typename Callable, typename... Args>
|
|
Thread(Callable&& f, Args&&... args);
|
|
};
|
|
|
|
template<typename Callable, typename... Args>
|
|
Thread::Thread(Callable&& f, Args&&... args) {
|
|
auto boundFunc = std::bind(std::forward<Callable>(f), std::forward<Args>(args)...);
|
|
|
|
auto funcPtr = new std::function<void()>(boundFunc);
|
|
|
|
#ifdef _WIN32
|
|
CreateThread(nullptr, 0, __thread, funcPtr, 0, nullptr);
|
|
#endif
|
|
}
|
|
|
|
} // namespace Chattr
|