How to properly handle a constantly hanging third-party library call in a C ++ stream?

I have a device with a library. Some of its functions are most terribly cruel, in the sense of "sometimes hanging forever."

I have a program that uses this device. If / when it freezes, I need to restore the grace and reset it. Abusive calls should return within milliseconds and be called in a loop many times per second.

My first question is : when a thread performing an unwavering function freezes, what should I do? Even if I clog a stream with breakpoints, this happens:

boost::this_thread::interruption_point(); // irrelevant, in the past
deviceLibrary.thatFunction(); // <-- hangs here forever
boost::this_thread::interruption_point(); // never gets here!

The only word I read about what to do is to change the function itself, but this is out of the question for a number of reasons - not least from the fact that "this is already beyond my skill set."

I tried asynchronous start with C ++ 11 flags:

// this was in a looping thread -- it does not work: wait_for sometimes never returns
std::future<void> future = std::async(std::launch::async, 
    [this] () { deviceLibrary.thatFunction(*data_ptr); }); 
if (future.wait_for(std::chrono::seconds(timeout)) == std::future_status::timeout) { 
    printf("no one will ever read this\n"); 
    deviceLibrary.reset(); // this would work if it ever got here
}

No dice in this or several variations.

Now I am trying boost::asiowith the thread_groupnumber of worker threads working under io_service::run(). It works great until the second time runs out. Then I ran out of flows, because each hanging stream absorbs one of mine thread_group, and it never returns.

work_threads.create_thread, . : , ? ? ?

, , deviceLibrary.thatFunction() . .

, # Windows, , . , (edit: oh right; . , . Hm...)

: MSVC 2013 Windows 7, - ARM Debian GCC 4.6. ++ - ... ... , - , , , .

!

+4
3

- , .

- "", , Chrome, . , , , .

Google Chrome , ?

, . .

, , flaky- , . - , .

+8

: , , , ?

. . , . , . (, , ), .

, , , , - , .

+1

, , , , . , ( ), . , .

What you don't do is put your fingers in your ears and say “LALALALALA” while you hide the problem behind the layers of crud, trying to pretend the problem is gone.

-3
source

All Articles