Throwing exception on thread end ?
-
Hi All ! I have read that the C# threading classes in .NET causes an exception to be thrown in a thread if that thread is being ended by another thread. Any idea's on how to implement this with VC 6.0 ? This could provide an excellent alternative to polling for stop flags. Kind regards, Alwin
-
Hi All ! I have read that the C# threading classes in .NET causes an exception to be thrown in a thread if that thread is being ended by another thread. Any idea's on how to implement this with VC 6.0 ? This could provide an excellent alternative to polling for stop flags. Kind regards, Alwin
March'96 issue of MSJ has the answer, unfortunately, it'll work on NT/2K/XP only. Check the 'QA Win32' by Jeffrey Richter. The article may be in MSDN installed on your HD, if it's not there, check the msdn.microsoft.com. Tomasz Sowinski -- http://www.shooltz.com
-
Hi All ! I have read that the C# threading classes in .NET causes an exception to be thrown in a thread if that thread is being ended by another thread. Any idea's on how to implement this with VC 6.0 ? This could provide an excellent alternative to polling for stop flags. Kind regards, Alwin
this is just an idea. U heard of 'atexit' . use it to register a fn, put the handle to the current thread in a global variable and inside the fn so some thing like this. HANDLE hOriginalThread ; viod ThreadFn() { atexit(fn) ; .. .. } void fn { if( GetCurrentThread()!= hOriginalThread) AfxThrowMemoryException() ; } U can work out the way out of global variable . One last thing, u means of throwning exception is alright but where will it be caught ?
-
Hi All ! I have read that the C# threading classes in .NET causes an exception to be thrown in a thread if that thread is being ended by another thread. Any idea's on how to implement this with VC 6.0 ? This could provide an excellent alternative to polling for stop flags. Kind regards, Alwin
There's a number of reasons why this cannot be achieved in general, the most important one being that the compiler often assumes portions of code throw no expceptions and takes advantage of this for optimization. Also, if there's floating point arithmetic involved the issue becomes even more tricky, as these operations are usually performed by a separate coprocessor (you can think of them as performed by a microthread), which yields the approach of "everything can throw an exception" a hard one to handle. Other, less important difficulties are those posed by the hard time programmers will have if they must assume everything can throw --think of how you'd prevent memory leaks in such situations. First releases of Java included this termination-by-exception approach, but later on they deprecated it for the reasons mentioned. Of course, these problems can be tackled in C# as this language runs in a strongly managed environment. The downside is resulting poor performance. That said, you can have a thread inspect for termination conditions and throw accordingly upon calling a selected set of DLL functions (even system functions from KERNEL32, USER32, etc.) Check PJ Naugter's HookImportFunctionByName v1.0 for details. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo