99901f55   
   From: pete@versatilecoding.com   
      
   On 2012-04-24 04:23:37 +0000, M J said:   
      
   > On 23 Apr., 16:47, Pete Becker wrote:   
   >> On 2012-04-23 17:37:46 +0000, nroberts said:   
   >>   
   >>> To take advantage of C++'s new threading stuff (the memory model and   
   >   
   > [...]   
   >> once functions   
   >   
   > What are once functions?   
      
   std::once_flag flag;   
   void initialization(int i) {   
    // whatever   
   }   
      
   std::call_once(flag, initialization, 3);   
      
   Regardless of how many times that call to call_once is made, and   
   regardless of how many threads it's called from, it will only call   
   initialization(3) once, the "first" time it's called. Typically used   
   for lazy initialization.   
      
   I put "first" in quotes because there is the possibility that the   
   called function (or function object) will throw an exception, which   
   isn't a successful call. It's really the first successful call, and if   
   you like throwing exceptions during initialization, you'll love the   
   description of the semantics when the called function can throw   
   exceptions.   
      
   --   
    Pete   
   Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The   
   Standard C++ Library Extensions: a Tutorial and Reference   
   (www.petebecker.com/tr1book)   
      
      
    [ 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)   
|