Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] thread problem  (Read 3189 times)

0 Members and 1 Guest are viewing this topic.

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
[Solved] thread problem
« 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.
Why can't things just work?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] thread problem
« Reply #1 on: August 07, 2008, 04:41:58 pm »
Your threads are stopped when your sf::Thread instances are destroyed.
Laurent Gomila - SFML developer

Kreeg

  • Full Member
  • ***
  • Posts: 115
    • View Profile
[Solved] thread problem
« Reply #2 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.
Attention (va) aux (sur) messages (mon) subliminaux, (blog) camarade !

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
[Solved] thread problem
« Reply #3 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);

Regen

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
[Solved] thread problem
« Reply #4 on: August 08, 2008, 09:30:29 am »
ahhhh, thanks a lot! works now:)
Why can't things just work?