Re: creating a new thread to run while loop
From: Marius Prisecaru (prisasm_at_h0tmail.remove-this-n-make-zero-o.com)
Date: 10/08/04
- Next message: Holi: "Error when installing Standard SDK for Windows CE.NET"
- Previous message: Arvind: "Re: eVC++ 4.0 Problem"
- In reply to: Bryan Gan: "Re: creating a new thread to run while loop"
- Next in thread: Corey Burke [MS]: "Re: creating a new thread to run while loop"
- Reply: Corey Burke [MS]: "Re: creating a new thread to run while loop"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Holi: "Error when installing Standard SDK for Windows CE.NET"
- Previous message: Arvind: "Re: eVC++ 4.0 Problem"
- In reply to: Bryan Gan: "Re: creating a new thread to run while loop"
- Next in thread: Corey Burke [MS]: "Re: creating a new thread to run while loop"
- Reply: Corey Burke [MS]: "Re: creating a new thread to run while loop"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|