Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Throwing exception on thread end ?

Throwing exception on thread end ?

Scheduled Pinned Locked Moved C / C++ / MFC
csharptutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alwin75
    wrote on last edited by
    #1

    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

    P T J 3 Replies Last reply
    0
    • A Alwin75

      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

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Alwin75

        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

        P Offline
        P Offline
        Prem Kumar
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • A Alwin75

          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

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups