[Pogamut-list] Threads

fireball787b pogamut-forum at diana.ms.mff.cuni.cz
Wed Feb 20 12:22:46 CET 2013


Re: Threads

Author: fireball787b

Hi Jimmy!

First of all, thanks for your help ^^

I just need to use the logic module. I'm working with the bots to create a better bot after a certain time, so in the logic module, every 20 seconds, each bot writes in a personal file it's own information (health, deads,...). After 2-3min one bot should stop the other bots and read all the files, create a new file with all the data from the bots and generate a new file for each bot. All these stuff is done in the logic module without pausing the threads. In this case the execution is quite good but almost always the execution fails because some bot is trying to read a file that doesn't exist yet.

I know there's always one thread which id is "10", so i decided that this thread will manage all the others.

if(thread_id == 10)
{
   Thread[] threads = new Thread[Thread.activeCount()];
   int numThreads = Thread.enumerate(threads);
   int index = 0;
   for (int i = 0; i < numThreads; i++)
   {
      if(((int)(threads[i].getId())) != 10)
      {
         synchronized(threads[i])
         {
            try{
            threads[i].wait()
            }
            catch(Inter...)
            { 
               System.err...
            }
         }
      }
   }
}

This is the code that i use to try to manage the bots. would you still using the same that you said before with the mutex?

Thanks for everything ^^

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=6&comments_parentId=1134&post_reply=1#form>




More information about the Pogamut-list mailing list