how do I handle a dll function that does not return?

Hi,

I am using visual C++ ver 8.

I have written a application that calls a third party dll function that communicates to a connect embedded device via TCP/IP. This routine is ran around 14 times a second.

Two/three weeks or so in, my application stops working due to a non return in the dll and appears to get stuck in a internal loop in the third party dll. The application does not crash and a simple closedown and restart gets things going again.

What is the best way to handle this? I know if I was using VB, I could maybe use a multi-threaded timer function to see if processing has stopped? However, I dont know how to do this in c++ or is is there a simpler method?

As its a third party dll I cant debug their issue, but I should be able to handle it.

I would appreciate your assistance?

VisionMan
Run the function on a separate thread and have the caller function wait for it to return for a set period of time. If the timeout expires before the function returns, forcibly kill the thread.
Note that any resources allocated by the function will not be released, so it may not be a bad idea to run it in a separate process and pass the data back and forth through IPC.
Thanks Helios,

so the function call should be ran as a seperate process? with a seperate thread acting as a timeout handler?


The timeout should be handled by the same thread you're currently using to call the DLL function. It would look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//main program startup code:
create_child_process();

//...

//inside the loop:
//call_DLL_function(data_result); //old code
//process_data(data_result);      //old code
if (call_DLL_function_from_child_process(data_result)==TIMEOUT_EXPIRED){
    //let the OS do the cleanup
    kill_child_process();
    create_child_process();
}else
    process_data(data_result);
Hi Helios,

Am I right in saying that a deadlock condition may occur if the child process does not terminate, the parent process will not proceed.

Regards,
Niall
Topic archived. No new replies allowed.