Windows has support for SIGINT in console applications in response to Ctrl-C. This implies Windows has functionality to interrupt a running thread from a remote thread (process even!) and invoke a signal handler.
Exactly how does this work at the NT Native API level开发者_C百科? Can this thread-interruption API be used for other purposes in userspace?
According to http://msdn.microsoft.com/en-us/library/xdkz3x12(v=vs.71).aspx, a SIGINT causes a new thread to be created to handle the interrupt.
So it looks like it doesn't really "interrupt" any running threads. You can achieve the same effect by simply spawning your own thread.
There is more commentary here:
- C++: Continue execution after SIGINT
- http://blogs.msdn.com/b/oldnewthing/archive/2008/07/28/8781423.aspx
You could always suspend the target thread, fix up the context to execute your procedure and then resume it. It's ugly but it would work if you wanted to interrupt a thread to execute a procedure.
The console and the CTRL+C handler are Win32 constructs and do't really exist at the native API level.
精彩评论