Fixing thread cancellation.
This commit is contained in:
parent
e82514a56a
commit
5a53d3681d
@ -118,6 +118,10 @@ int NeoComm_bind(const unsigned short port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *NeoComm_connect_manager() {
|
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)
|
while(run)
|
||||||
{
|
{
|
||||||
int cli_sockfd;
|
int cli_sockfd;
|
||||||
@ -181,15 +185,13 @@ void NeoComm_shutdown_directory() {
|
|||||||
if(!node_list)
|
if(!node_list)
|
||||||
return;
|
return;
|
||||||
run = 0;
|
run = 0;
|
||||||
void *res;
|
pthread_cancel(accept_thread);
|
||||||
for(unsigned int i = 0; i < num_nodes; ++i)
|
for(unsigned int i = 0; i < num_nodes; ++i)
|
||||||
{
|
{
|
||||||
// in case the threads are still running, we wait
|
pthread_cancel(node_list[i].thread);
|
||||||
pthread_join(node_list[i].thread, &res);
|
|
||||||
close(node_list[i].sockfd);
|
close(node_list[i].sockfd);
|
||||||
}
|
}
|
||||||
num_nodes = 0;
|
num_nodes = 0;
|
||||||
pthread_join(accept_thread, &res);
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
||||||
free(node_list);
|
free(node_list);
|
||||||
|
Loading…
Reference in New Issue
Block a user