mirror of
https://github.com/fumiama/simple-kanban.git
synced 2026-06-29 23:51:09 +08:00
尝试解决高并发时子线程崩溃
This commit is contained in:
17
server.c
17
server.c
@@ -270,20 +270,24 @@ void accept_timer(void *p) {
|
|||||||
while(!pthread_kill(*(timer->thread), 0)) {
|
while(!pthread_kill(*(timer->thread), 0)) {
|
||||||
sleep(MAXWAITSEC);
|
sleep(MAXWAITSEC);
|
||||||
puts("Check accept status");
|
puts("Check accept status");
|
||||||
if(!*(timer->thread)) {
|
if(time(NULL) - timer->touch > MAXWAITSEC) {
|
||||||
free(timer);
|
|
||||||
break;
|
|
||||||
} else if(time(NULL) - timer->touch > MAXWAITSEC) {
|
|
||||||
kill_thread(timer);
|
kill_thread(timer);
|
||||||
free(timer);
|
free(p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kill_thread(THREADTIMER* timer) {
|
void kill_thread(THREADTIMER* timer) {
|
||||||
|
if(*(timer->thread)) {
|
||||||
pthread_kill(*(timer->thread), SIGQUIT);
|
pthread_kill(*(timer->thread), SIGQUIT);
|
||||||
|
*(timer->thread) = 0;
|
||||||
|
puts("Kill thread.");
|
||||||
|
}
|
||||||
|
if(timer->accept_fd) {
|
||||||
close(timer->accept_fd);
|
close(timer->accept_fd);
|
||||||
|
timer->accept_fd = 0;
|
||||||
|
}
|
||||||
if(timer->data) {
|
if(timer->data) {
|
||||||
free(timer->data);
|
free(timer->data);
|
||||||
timer->data = NULL;
|
timer->data = NULL;
|
||||||
@@ -294,8 +298,6 @@ void kill_thread(THREADTIMER* timer) {
|
|||||||
timer->is_open = 0;
|
timer->is_open = 0;
|
||||||
puts("Close file.");
|
puts("Close file.");
|
||||||
}
|
}
|
||||||
*(timer->thread) = 0;
|
|
||||||
puts("Kill thread.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_pipe(int signo) {
|
void handle_pipe(int signo) {
|
||||||
@@ -326,6 +328,7 @@ void handle_accept(void *p) {
|
|||||||
}
|
}
|
||||||
printf("Break: recv %zd bytes\n", timer_pointer_of(p)->numbytes);
|
printf("Break: recv %zd bytes\n", timer_pointer_of(p)->numbytes);
|
||||||
} else puts("Error allocating buffer");
|
} else puts("Error allocating buffer");
|
||||||
|
timer_pointer_of(p)->thread = 0;
|
||||||
kill_thread(timer_pointer_of(p));
|
kill_thread(timer_pointer_of(p));
|
||||||
} else puts("Error accepting client");
|
} else puts("Error accepting client");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user