I have a problem with long running boost::regex_match(...)
invocation in a threaded process environment. But it could be another lib (API call) having the same problem.
Is there a generic way to set up a watchdog for such?
For non-threaded process alarm()
can be used to detect timeout.
However, signals don't play nicely with threads. I can avoid direct use of alarm()
in the thread and delegate timer mgt. to a dedicated separate thread and let that one use pthread_kill(...)
to address the correct threads (this is just an idea - i didn't yet verify that part).
However, also this only interrupts and detects the situation, but cannot gracefully stop boost::regex_match(...)
.
I played around with Throwing an exception from within a signal handler using sigsetjmp()
and siglongjmp()
for the thread using boost::regex_match(..)
.
But it causes memory leaks in boost::regex_match(...) because
siglongjmp()` bypasses destructors.
How can i gracefully stop a 3rd party API call - presuming that it's implemented exception safe?
Or does it have to be supported by some "stoppable" feature actively implemented in the 3rd party API? (is there some for the boost library?)
Maybe some strange idea, but:
Code can be implemented to be "thread-safe" and/or "exception-safe".
Would it be an option to define "longjmp-safe"? This could be done by passing an additional token to a lib to let is associate all resource allocations to that token. After longjmp()
the client SW could ask the API separately to release those resources.
simpler maybe would just be some central init()/release() or register()/unregister() API call, by which the API could clean-up itself.