thread detach 완성
This commit is contained in:
12
Server/src/Chattering.log
Normal file
12
Server/src/Chattering.log
Normal 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...
|
||||
@@ -41,6 +41,8 @@ int main() {
|
||||
|
||||
Chattr::Thread t1([]() {
|
||||
spdlog::info("thread?");
|
||||
sleep(1);
|
||||
spdlog::info("thread?");
|
||||
});
|
||||
|
||||
spdlog::info("Waiting for connection...");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user