home bbs files messages ]

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 32,552 of 33,346   
   fmatthew5876 to All   
   IO thread, block or destroy/recreate   
   20 Sep 12 21:23:33   
   
   From: fmatthew5876@googlemail.com   
      
   I have a game engine where I want to queue asynchronous IO requests   
   and poll every frame until they are all finished. This is using C++   
   std::thread and friends.   
      
   Basically the work flow of the main thread is like this:   
      
   1. queue io requests   
   2. check if done == false   
   3. check if done == false   
   ....   
   n. check if done == true; flush()   
      
   Then the game runs for a long time until its ready to load the next   
   set of game resources.   
      
   After calling flush(), all of the IO resources are loaded and   
   synchronization is complete. My question now is what to do with the IO   
   thread.   
      
   One option is to let it exit and join() it. Then later when I want to   
   queue up a new set of IO's I have to recreate the thread.   
      
   The other option is to let it block on a condition variable   
   indefinatly until a new IO request is given.   
      
   The second option would be easier to implement and also would result   
   in less latency for each set of IO requests as waking up a blocked   
   thread is faster than creating a new one. Are there downsides to   
   keeping an active thread alive in the blocked state? Is it really   
   wasteful of resources? Is it possible that on some implementations   
   this would result in wasteful busy waiting by the other thread?   
      
   Thank you for your help!   
      
      
   --   
         [ 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