SFML community forums

Help => General => Topic started by: Regen on August 07, 2008, 02:11:08 pm

Title: [Solved] thread problem
Post by: Regen on August 07, 2008, 02:11:08 pm
I have a server-client application. The server is suppsoed to identify the client connecting and then start the acording thread for the client, after that it should continue to lissen for other clients. This is a part of the code:
ClientIncomming() is returning the client-socket to the global variable Sock.

   
Code: [Select]
do{
Client = ClientIncomming(4567);
Client.Receive(Pack);
Pack >> Type;

if(Type == "Boss" && !BossThread){
sf::Thread Boss(&Boss);
Boss.Launch();
}
else if(Type == "Shooter" && !ShooterThread){
sf::Thread Shooter(&Shooter);
Shooter.Launch();
}
else if(Type != "Boss" || Type != "Shooter")
std::cout << "Undefined Client tried to connect, rejected" << std::endl;


}while(1);


The thing is...the threads dont really act like threads, they act lika normal functions...

anyone have any idea? please ask me if you want some other part of the code.
Title: [Solved] thread problem
Post by: Laurent on August 07, 2008, 04:41:58 pm
Your threads are stopped when your sf::Thread instances are destroyed.
Title: [Solved] thread problem
Post by: Kreeg on August 07, 2008, 04:55:30 pm
They are destroyed when you leave the scope of an 'if' or 'else if' statement, because they are local instances.
Title: [Solved] thread problem
Post by: Wizzard on August 07, 2008, 11:40:39 pm
Code: [Select]
sf::Thread Boss(&Boss);
sf::Thread Shooter(&Shooter);

do{
      Client = ClientIncomming(4567);
      Client.Receive(Pack);
      Pack >> Type;

      if(Type == "Boss" && !BossThread){
         Boss.Launch();
         }
      else if(Type == "Shooter" && !ShooterThread){
         Shooter.Launch();
         }
      else if(Type != "Boss" || Type != "Shooter")
         std::cout << "Undefined Client tried to connect, rejected" << std::endl;


   }while(1);
Title: [Solved] thread problem
Post by: Regen on August 08, 2008, 09:30:29 am
ahhhh, thanks a lot! works now:)