From bec298d7266441fad41d2fd96972e7bfd409e053 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: Sat, 15 Oct 2022 11:13:26 +0800 Subject: [PATCH] try to fix sigsegv --- server.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server.c b/server.c index ab6d1e8..c80f9d9 100644 --- a/server.c +++ b/server.c @@ -657,8 +657,6 @@ static void handle_pipe(int signo) { } static void handle_accept(void *p) { - pthread_cond_init(&timer_pointer_of(p)->c, NULL); - pthread_mutex_init(&timer_pointer_of(p)->mc, NULL); pthread_cleanup_push((void*)&cleanup_thread, p); puts("Handling accept..."); while(1) { @@ -858,11 +856,15 @@ static void accept_client(int fd) { pthread_cond_signal(&timer->c); // wakeup thread pthread_mutex_unlock(&timer->mc); puts("Pick thread from pool"); - } else if (pthread_create(&timer->thread, &attr, (void *)&handle_accept, timer)) { - perror("Error creating thread"); - cleanup_thread(timer); - putchar('\n'); - } else puts("Thread created"); + } else { + pthread_cond_init(&timer_pointer_of(p)->c, NULL); + pthread_mutex_init(&timer_pointer_of(p)->mc, NULL); + if (pthread_create(&timer->thread, &attr, (void *)&handle_accept, timer)) { + perror("Error creating thread"); + cleanup_thread(timer); + putchar('\n'); + } else puts("Thread created"); + } } }