From e1287d0c9a20a191733cb8bf6f6dc510cdeaad1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 27 Oct 2022 18:36:10 +0800 Subject: [PATCH] fix --- server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server.c b/server.c index 5f0fb4a..5f5561d 100644 --- a/server.c +++ b/server.c @@ -626,12 +626,11 @@ static void accept_timer(void *p) { sigaddset(&mask, SIGPIPE); // 防止处理嵌套 pthread_sigmask(SIG_BLOCK, &mask, NULL); - pthread_rwlock_unlock(&timer->mt); - sleep(MAXWAITSEC / 4); - pthread_rwlock_rdlock(&timer->mt); + thread = timer->thread; pthread_rwlock_unlock(&timer->mt); + while(thread && !pthread_kill(thread, 0)) { pthread_rwlock_rdlock(&timer->mb); uint8_t isbusy = timer->isbusy; @@ -918,6 +917,7 @@ static void accept_client(int fd) { } else { pthread_cond_init(&timer->c, NULL); pthread_mutex_init(&timer->mc, NULL); + pthread_rwlock_wrlock(&timers[p].mt); if (pthread_create(&timer->thread, &attr, (void *)&handle_accept, timer)) { perror("Error creating thread"); cleanup_thread(timer);