diff --git a/src/connectivity.c b/src/connectivity.c index ea13585..0cdf96e 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -118,6 +118,10 @@ int NeoComm_bind(const unsigned short port) { } void *NeoComm_connect_manager() { + // Allow for thread to be cancelled asynchronously + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + while(run) { int cli_sockfd; @@ -181,15 +185,13 @@ void NeoComm_shutdown_directory() { if(!node_list) return; run = 0; - void *res; + pthread_cancel(accept_thread); for(unsigned int i = 0; i < num_nodes; ++i) { - // in case the threads are still running, we wait - pthread_join(node_list[i].thread, &res); + pthread_cancel(node_list[i].thread); close(node_list[i].sockfd); } num_nodes = 0; - pthread_join(accept_thread, &res); close(sockfd); free(node_list);