Fixing thread cancellation.

This commit is contained in:
Nicolás Ortega Froysa 2017-08-05 16:38:24 -05:00
parent e82514a56a
commit 5a53d3681d
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF

View File

@ -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);