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();
deviceLibrary.thatFunction();
boost::this_thread::interruption_point();
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:
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();
}
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. ++ - ... ... , - , , , .
!