c - Why is pthread_join not returning? -


I think pthread_join should always return one value and then allow the main thread to process the code after that . In my previous experience, this will work, but now I am stuck with it. Somehow it does not just return and blocks the main thread. Or this is the main thread that executes the work. I do not know why in the code below, I can not reach the "made thread" until I can finish the client. Any ideas?

  int main (int argc, char * argv []) {int sockfd, port; / * Listen to Sock_fd, new_fd * / struct sockaddr_in new connection on my_addr; / * My address information * / struct sockaddr_in their_addr; / * Connector address information * / socklen_t sin_size; If (signet, sigintEvent == SIG_ERR) printf ("can not hold SIGINT!"); / * Generate socket / if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {glitch ("socket"); Exit (1); } If (argc> 1) {port = atoi (argv [1]); } And {port = MYPORT; } / * End point * / my_addr.sin_family = generate AF_INET; / * Host byte order * / my_addr.sin_port = htons (port); / * Low, network byte order * / my_addr.sin_addr.s_addr = INADDR_ANY; / * Autofill with my IP * / / * berboo (and (my_addr.sin_zero, 8); ZJL * / / * Rest of the structure * / / * Tie the socket at the end point / / * (Bound (Sokfed, (Structure Sokadar *) and Mai_Add, Psychof (Structure Sokadar)) = = 1) {Mirror ("Tie" ); Exit (1); } / * Starting list of listings * / if (listen (sokfad, maxconnection) == -1) {false ("listen"); Exit (1); } Create pools (MAXCONNECTIONS); / * Create a node pointer as the top of the list * / head = (node ​​*) malloc (sizeof (node)); Open file (); Printf ("The list of server list starts ... \ n"); Int new_fd; Sin_size = sizeof (structure sockaddr_in); While ((new_fd = accept (sockfd, (struct sockaddr *) and their_addr, and sin_size)) {printf ("Approved! \ N"); Printf ("server: connection found! \ N"); // tNode * tThread = (tNode *) threadedique (); Pthread_t pt; Printf ("TTThread found. \ N"); If ((pthread_create (& amp; pt, NULL, runService, (* * * zero and new_fd)) = 0) {printf ("Error creating thread"); Abortion (); } Printf ("Thread Created. \ N"); If (pthread_join (pt, NULL)! = 0) {printf ("Error in engagement"); Abortion (); } Printf ("Thread Created 2. \ N"); } Exit (1); }  

From the document we can read the following information about blockquote

Pthread_join () function waits for the thread specified by the formula to finish If the thread is already finished, then pthread_join () comes back immediately. The thread specified by the thread should be additive.

This indicates that in your case the parent thread is waiting for the completion of your child's thread pt . The child thread pt that is running runService is still not back / done, so your parent thread is waiting for completion (not returning with the pthread_join method).

You should try to review the runService code to understand this situation.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -