Re: creating a new thread to run while loop

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Marius Prisecaru (prisasm_at_h0tmail.remove-this-n-make-zero-o.com)
Date: 10/08/04


Date: Fri, 8 Oct 2004 09:13:34 -0400

Hi,

> since my sending operation is not able to time out and return error if the
> connection suddenly dropped, so i have to go for an alternative which
create
> a thread out and invoke the timer for the specified interval. therefor,
under
> wm_timer message, will check on a flag variable whether communication
process
> still running. if no, then will generate error. hope this is clear.

You have a serious problem here. If the send operation (started in any
thread) is not able to timeout / return error / etc and is basically being
'blocked' waiting forever (if the connection is dropped) there is not a
whole lot you can do. Think about it... let's say we are in some thread and
the following lines of code execute:

line 1... ok
line 2... ok
send(...) <<-- thread is waiting for this to return in order to continue...
but it never does since you are saying it is not able to timeout in case of
a problem...

What options do you have at this point ? .. sure, you can have a different
thread measure the time from when the send was initiated to some time later
based on a timeout value... but suppose it finds out that the time period
elapsed and still it did not receive any info that the send has been
completed... what should it do then ? How is it going to terminate the send
in order to have it 'retry' ? The only options seems to be to terminate the
thread that contains the send operation... but how ? TerminateThread ?
ExitThread ? These are functions that should only be used in EXTREME cases
(where for example you're preventing a total system shutdown) so they should
be avoided since they cause the thread to leak handles, not deallocate
resources ( no destructors called), dlls attached to threads would not be
notified about the thread's termination and so on....

The example that you supplied w/ the loop in the main thread that causes the
thread not to receive any messages but only after the loop has finished is
exactly the scenario that would happen w/ a send that cannot timeout. While
in the loop example you may be able to process messages in the loop itself,
in this other scenario you probably have no control on the implementation of
the 'send' method thus it would really need to complete before it could do
anything else.

So the question arises, why is the send not being able to timeout ? What
kind of communication functions/classes are you using ?

Marius



Relevant Pages

  • TCP timeout problem
    ... A timeout never occurs and the connection will not terminate. ... Thx in advance ...
    (Linux-Kernel)
  • Re: SELECT statement (Time Out)
    ... Actually it would be the CommandTimeOut that would terminate the process if ... max amount of time it would take to establish the connection. ... > connection timeout setting the connection will be terminated. ... Blocked statements don't timeout but ...
    (microsoft.public.sqlserver.programming)
  • Re: OE6 does not connect with pop3 server
    ... Can we infer from this that you got a timeout on the EarthLink account ... My point about making an approximate timestamp is just to look at the ... E.g. as near as possible before the connection ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Timout control with RPC/HTTP
    ... specifies the minimum connection timeout used by the ... client and RPC Proxy, in seconds. ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.exchange.admin)
  • Re: Timout control with RPC/HTTP
    ... please also check the RPC web site connection timeout settings ... Maybe the idle timeout settings depend on here. ...
    (microsoft.public.exchange.admin)