From: Shuanglei Tao Date: Sat, 20 Apr 2019 23:16:34 +0000 (+0800) Subject: protocol: do not block main thread when destroying client X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=d5a542d0dcc625607593240fdb64c92d7b39690d;p=ttyd.git protocol: do not block main thread when destroying client --- diff --git a/src/protocol.c b/src/protocol.c index 027cdff..ca6fe3c 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -135,10 +135,11 @@ tty_client_destroy(struct tty_client *client) { client->running = false; - pthread_mutex_lock(&client->mutex); - client->state = STATE_DONE; - pthread_cond_signal(&client->cond); - pthread_mutex_unlock(&client->mutex); + if (pthread_mutex_trylock(&client->mutex)) { + client->state = STATE_DONE; + pthread_cond_signal(&client->cond); + pthread_mutex_unlock(&client->mutex); + } // kill process (group) and free resource int pgid = getpgid(client->pid);