Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,568 of 33,346    |
|    red floyd to All    |
|    Re: Windows' ExitThread() and clasess' d    |
|    15 Oct 11 08:59:29    |
   
   6d05f4dd   
   From: no.spam.here@its.invalid   
      
   On 10/15/2011 5:18 AM, Camilo Bravo Valdés wrote:   
   > Hello.   
   >   
   > I have read that some Windows API functions like ExitThread() do not   
   > call the destructors of classes. Is this true? Is then useless to   
   > follow the RAII principle when working with the Windows API? Are there   
   > "safer" versions of this function?   
   > { OS independant replies only please - mod}   
   >   
      
   I think this is common to all threading API's. C++11 may fix this,   
   but if you're using an C++03 compiler, try defining a special exception,   
   and catch it only in the top level thread function. The exception   
   propagation will call your destructors and then when you exit the top   
   level thread function, the thread will terminate.   
      
      
   struct TerminateThread {   
    int const exit_code;   
    TerminateThread(int x) : exit_code(x) { }   
   };   
      
   int thread_function()   
   {   
    try {   
    // do stuff   
    // exit normally   
    }   
    catch (TerminateThread e) {   
    return e.exit_code;   
    }   
   }   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca