Subj : Re: pthreads: cancelling thread blocked on berkeley socket accept() To : comp.programming.threads From : David Hopwood Date : Tue Sep 20 2005 12:23 am 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. Otherwise the accept() just gets an EBADF and the thread exits anyway. In shutdown code, you're presumably not opening any new file descriptors. OTOH, I agree that using shutdown() is better. -- David Hopwood .