Thread 일부 구현

This commit is contained in:
2025-04-23 07:13:43 +09:00
parent 338462ab61
commit aaaf706feb
3 changed files with 39 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
#include "Socket/TCPSocket.hpp"
#include "Socket/Log.hpp"
#include "Utils/ConfigManager.hpp"
#include "Utils/Thread.hpp"
#include "precomp.hpp"
int main() {
@@ -37,6 +39,10 @@ int main() {
else
clientAddr.length = sizeof(sockaddr_in6);
Chattr::Thread t1([]() {
spdlog::info("thread?");
});
spdlog::info("Waiting for connection...");
sock.accept(clientSock, clientAddr);
}

2
impl/Utils/Thread.cpp Normal file
View File

@@ -0,0 +1,2 @@
#include "Utils/Thread.hpp"

View File

@@ -5,4 +5,34 @@
#else
#error "이 플랫폼은 지원되지 않습니다."
#endif
#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