Subj : Re: Threading and Timeouts To : comp.programming.threads From : David Schwartz Date : Mon Jul 18 2005 04:12 pm "MC" wrote in message news:p89od1hfi9dm4hff0dbf942uocqb57q9r5@4ax.com... > 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?? If you want timeouts, don't use synchronous API calls. As a simple fix , if you're only dealing with a single connection, you can use 'select' and make the socket non-blocking. DS .