Subj : Re: pthreads: cancelling thread blocked on berkeley socket accept() To : comp.programming.threads From : David Schwartz Date : Mon Sep 19 2005 08:35 pm "David Hopwood" wrote in message news:hMHXe.598$WV1.130@fe2.news.blueyonder.co.uk... > David Schwartz wrote: >> "David Hopwood" wrote: >>>You should set a shared 'shouldExit' flag and close() the socket from the >>>main thread. The listening thread will get an error from the accept(), >>>and >>>can then exit when it sees that 'shouldExit' is set. >> Note that this is a very dangerous thing to do and should only be >> done >> as part of a shutdown process. It can cause terrible corruption. > Only if the file descriptor has been reused. Something over which you have no control. > Otherwise the accept() just > gets an EBADF and the thread exits anyway. In shutdown code, you're > presumably > not opening any new file descriptors. Suppose some library has a license checked out from a license server. On shutdown it may need to release that license. Suppose this program is registered as available in a central tracking server and on shutdown goes to unregister. > OTOH, I agree that using shutdown() is better. Definitely. DS .