thread detach 완성

This commit is contained in:
2025-04-24 21:36:48 +09:00
parent 07cff49813
commit c660c41657
6 changed files with 26 additions and 2 deletions

12
Server/src/Chattering.log Normal file
View File

@@ -0,0 +1,12 @@
[2025-04-24 21:34:04.752] [Chattering Logger] [info] thread?
[2025-04-24 21:34:04.752] [Chattering Logger] [info] Waiting for connection...
[2025-04-24 21:34:24.926] [Chattering Logger] [info] thread?
[2025-04-24 21:34:24.926] [Chattering Logger] [info] Waiting for connection...
[2025-04-24 21:34:39.658] [Chattering Logger] [info] thread?
[2025-04-24 21:34:39.658] [Chattering Logger] [info] Waiting for connection...
[2025-04-24 21:34:48.422] [Chattering Logger] [info] Waiting for connection...
[2025-04-24 21:34:48.422] [Chattering Logger] [info] thread?
[2025-04-24 21:34:49.422] [Chattering Logger] [info] thread?
[2025-04-24 21:35:32.526] [Chattering Logger] [info] thread?
[2025-04-24 21:35:33.526] [Chattering Logger] [info] thread?
[2025-04-24 21:35:33.526] [Chattering Logger] [info] Waiting for connection...

View File

@@ -41,6 +41,8 @@ int main() {
Chattr::Thread t1([]() {
spdlog::info("thread?");
sleep(1);
spdlog::info("thread?");
});
spdlog::info("Waiting for connection...");

View File

@@ -2,7 +2,8 @@
namespace Chattr {
Thread::~Thread() {
join();
if (!detached)
join();
}
void Thread::join() {
@@ -12,4 +13,11 @@ void Thread::join() {
pthread_join(handle_, NULL);
#endif
}
}
void Thread::deatch() {
detached = true;
}
}

View File

@@ -41,6 +41,7 @@ public:
~Thread();
void join();
void deatch();
private:
#ifdef _WIN32
@@ -48,6 +49,7 @@ private:
#elif __linux__
pthread_t handle_;
#endif
bool detached = false;
};
} // namespace Chattr