Subj : Re: Threading and Timeouts To : comp.programming.threads From : Joe Seigh Date : Mon Jul 18 2005 07:17 pm MC wrote: > Hi all, > > Please let me know if there's a more appropriate group for my > question--perhaps a Windows group. I suspect it's more of a general > threading Q though... > > First off, I'm in the WinAPI environment and I'm finding that > asynchronous API calls for connecting to an FTP server are very > tedious. I'd prefer not to deal with all the states and handles if > possible--hence the idea of using synchronous API calls in a separate > thread. Here's the question: if the main thread creates a worker > thread and the worker makes a synchronous call--say to connect to the > FTP server--what's the best way to implement a timeout on that call? > What I've thought of so far is: > > main thread starts a timer > main thread starts worker thread > if timer ticks before worker is complete then terminate worker thread > > However, according to MSDN, terminating a thread should only be used > as a last resort because it doesn't do proper cleanup. But then how > else can a timeout be implemented, given that the worker thread is > busy in a synchronous API call? Am I doing this all wrong?? > Use non-blocking i/o with select() or poll(). Or just indicate i/o has timed out without "canceling" it, just let the i/o complete normally. Socket connections can't be shutdown instantaneously anyway. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .