#pragma once #ifdef _WIN32 #include #elif __linux__ #include #else #error "이 플랫폼은 지원되지 않습니다." #endif #include namespace Chattr { class Thread { public: #ifdef _WIN32 static DWORD WINAPI thread_func(LPVOID param) { std::unique_ptr> func(static_cast*>(param)); (*func)(); return 0; } #elif __linux__ static void* thread_func(void *param) { std::unique_ptr> func(static_cast*>(param)); (*func)(); return 0; } #endif template Thread(Callable&& f, Args&&... args); private: #ifdef _WIN32 HANDLE handle_; #elif __linux__ pthread_t handle_; #endif }; template Thread::Thread(Callable&& f, Args&&... args) { auto boundFunc = std::bind(std::forward(f), std::forward(args)...); auto funcPtr = new std::function(boundFunc); #ifdef _WIN32 handle_ = CreateThread(nullptr, 0, thread_func, funcPtr, 0, nullptr); #elif __linux__ pthread_create(&handle_, NULL, thread_func, funcPtr); #endif } } // namespace Chattr