I have a thread that listens for new connections
new_fd = accept(Listen_fd, (struct sockaddr *) & their_addr, &sin_size);
and anoth
Are you checking the return value of close? From linux manpages, (http://www.kernel.org/doc/man-pages/online/pages/man2/close.2.html) "It is probably unwise to close file descriptors while they may be in use by system calls in other threads in the same process. Since a file descriptor may be reused, there are some obscure race conditions that may cause unintended side effects". You can use a select instead of an accept and wait for some event from the other thead, then close the socket in the listener thread.