Subj : Re: Threading and Timeouts To : comp.programming.threads From : MC Date : Tue Jul 19 2005 03:59 am Thanks to both for your replies! I probably should have mentioned that I'm not using sockets--I'm using the Windows Internet (WinINet) API so, although I don't know much about select()/poll(), I'm guessing those are not an option for me. I do like the suggestion of just letting the synchronous call complete normally after the timeout. I'll try that. Thanks again, Craig On Mon, 18 Jul 2005 18:17:24 -0400, Joe Seigh wrote: >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. .