This is a mirror of official site: http://jasper-net.blogspot.com/

Exception injection: Throwing an exception in other thread

| Sunday, April 11, 2010
This article shows a way to "abort" a non-cooperating thread. More precisely, it can be used to abort some non-cooperating function called from another thread, and return execution to some "friendly" point within that thread. The method described in this article causes an exception to be raised in the target thread (similar to Thread.Abort  in .NET).
The method

First let's agree on the exception type that we may want to throw. Let's call it ThreadAbort and define it:

class ThreadAbort
{
__declspec (noreturn) static void Throw();
public:
static bool RaiseInThread(HANDLE hThread);
static void DontOptimize() throw (...);
};


Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: