I am working on a project where I make use of the lp_solve 5.5.0.13 DLL to solve many integer programming (IP) problems in succession. I set the timeout to 1s in order to speed up the calculations. Sometimes the solving procedure hangs.

In order to account for this I would like to start the call to the DLL to solve the IP in a new thread. That is easy. I would like to kill the thread if it hangs in order to make my program more robust. I would like to do so by timing the thread. If the thread is still active after, say 2s (1s more than my timeout limit), I would like to abort it and continue with the remaining calculations.

How should I go about doing this without waiting 2s for the threads that do not hang? The current threat should also not continue until the new thread (calculating the IP) is closed. How do I do this?