Click here to Skip to main content
15,887,886 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to wait for thread & if no response within time abort it Pin
karmendra_js14-Sep-05 19:32
karmendra_js14-Sep-05 19:32 
AnswerRe: How to wait for thread & if no response within time abort it Pin
PJ Arends14-Sep-05 19:52
professionalPJ Arends14-Sep-05 19:52 
GeneralRe: How to wait for thread & if no response within time abort it Pin
karmendra_js14-Sep-05 21:05
karmendra_js14-Sep-05 21:05 
GeneralRe: How to wait for thread & if no response within time abort it Pin
HumanOsc14-Sep-05 21:59
HumanOsc14-Sep-05 21:59 
GeneralRe: How to wait for thread & if no response within time abort it Pin
David Crow15-Sep-05 7:43
David Crow15-Sep-05 7:43 
GeneralRe: How to wait for thread & if no response within time abort it Pin
ThatsAlok15-Sep-05 18:15
ThatsAlok15-Sep-05 18:15 
GeneralRe: How to wait for thread & if no response within time abort it Pin
David Crow16-Sep-05 2:18
David Crow16-Sep-05 2:18 
AnswerRe: How to wait for thread & if no response within time abort it Pin
Roger Stoltz14-Sep-05 21:45
Roger Stoltz14-Sep-05 21:45 
Without knowing your exact problem I have a feeling that you should have another design session.Unsure | :~

It seems to me like you are writing both the driver and some app that uses the driver and you have mixed up the responsabilities for a successful write operation between the two.
I assume we are talking about a blocking call, otherwise I don't see the problem.
The return value from the write operation in the driver should tell the caller whether the operation was successful or not. For the write operation to be successful an ACK is required from the device.
Usually I tend to solve problems like this by having a thread that reads incoming data and maybe even interpret the data. In case of an ACK I would set an event that the write function waits for before returning with a call to WaitForSingleObject. The timeout should be reasonably short to be able to return as fast as possible, but yet long enough to give the device a chance to respond.
In case of a timeout the write operation should return a value that informs the caller that the operation failed and why, if possible.

If I'm wrong in my assumptions above, here's what you asked for:
if( ::WaitForSingleObject( hThread, 100 ) == WAIT_TIMEOUT )
{
    ::ExitThread( hThread );
}
::CloseHandle( hThread );

Note that ::CloseHandle does not terminate the thread, you have to use ::ExitThread() for that and afterwards close all handles to the thread.

Hope this helps
--
Roger
GeneralRe: How to wait for thread & if no response within time abort it Pin
karmendra_js14-Sep-05 22:04
karmendra_js14-Sep-05 22:04 
GeneralRe: How to wait for thread & if no response within time abort it Pin
HumanOsc14-Sep-05 22:40
HumanOsc14-Sep-05 22:40 
AnswerRe: How to wait for thread & if no response within time abort it Pin
karmendra_js14-Sep-05 23:03
karmendra_js14-Sep-05 23:03 
GeneralRe: How to wait for thread & if no response within time abort it Pin
Roger Stoltz14-Sep-05 23:22
Roger Stoltz14-Sep-05 23:22 
GeneralRe: How to wait for thread & if no response within time abort it Pin
karmendra_js14-Sep-05 23:43
karmendra_js14-Sep-05 23:43 
GeneralRe: How to wait for thread & if no response within time abort it Pin
Roger Stoltz15-Sep-05 1:53
Roger Stoltz15-Sep-05 1:53 
QuestionAbout CString : Plz Send Urgently Pin
parims14-Sep-05 19:08
parims14-Sep-05 19:08 
AnswerRe: About CString : Plz Send Urgently Pin
karmendra_js14-Sep-05 19:45
karmendra_js14-Sep-05 19:45 
AnswerRe: About CString : Plz Send Urgently Pin
prasad_som14-Sep-05 19:51
prasad_som14-Sep-05 19:51 
AnswerRe: About CString : Plz Send Urgently Pin
kakan14-Sep-05 20:03
professionalkakan14-Sep-05 20:03 
AnswerRe: About CString : Plz Send Urgently Pin
vikas amin15-Sep-05 1:11
vikas amin15-Sep-05 1:11 
JokeRe: About CString : Plz Send Urgently Pin
prasad_som15-Sep-05 2:16
prasad_som15-Sep-05 2:16 
AnswerRe: About CString : Plz Send Urgently Pin
YoSilver15-Sep-05 14:35
YoSilver15-Sep-05 14:35 
GeneralRe: About CString : Plz Send Urgently Pin
ThatsAlok15-Sep-05 18:11
ThatsAlok15-Sep-05 18:11 
Questionwhy does only a part of VARIANT change from VT_DATE to VT_BSTR? Pin
liuyue14-Sep-05 18:43
liuyue14-Sep-05 18:43 
Questionwrite Text on sphere Pin
cofd14-Sep-05 18:42
cofd14-Sep-05 18:42 
AnswerRe: write Text on sphere Pin
User 58385214-Sep-05 18:46
User 58385214-Sep-05 18:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.