I am trying to improve portability of a C ++ application using boost: threads instead of our own shell on top of Win32 threads, and the problem of gracefully terminating a thread (again) returns its ugly head.
In pure win32, I “interrupt” threads using QueueUserAPC to throw a “thread_interrupt” exception that causes all RAII objects to be cleared as described here . Any "warning" function of the OS can be interrupted this way, so things like mutexes, expectations, sleep mode, serial and socket I / O are all possible breakpoints.
However boost: mutexes, etc. are not “warned” by QueueUserAPC on win32 - they call things like Sleep (n), not SleepEx (n, true))
Threads with a thread have an “interrupt” mechanism (which similarly includes an exception), but it seems to have a drawback that ONLY raises :: thread calls are interrupted, so a third-party socket library (for example) cannot be interrupted.
What to do? I could change the source of the promotion locally to make it interruptible, but this seems like a bad choice, and I don't think it helps portability. Redesigning the entire app to remove the requirement for an elegant stream outage is also an unattractive route ...
Roddy source share