Does pthread_cancel works if the thread is running blocking code like accept connection?

Viewed 1597

I am beginner to C programming I created a new thread and its working fine ,my thread blocks the code at accept.Does calling pthread_cancel from outside terminates the thread.Or do I need to close the socket from outside.

Inside thread code it is a blocking code

 while( (clientfd = accept(socketfd, (struct sockaddr *)&client,&clilen)) )
        {
                printf("New Client connected");
                ......
        }

Calling pthread_cancel from outside

pthread_cancel(thread_id);

What happens?

2 Answers
Related