i'm working on a chat massenger, in my program i've written two threads as follows. i'm facing problem with there working. here is the main function of the program
int main()
{
char ipAddress[20];
getIp(ipAddress);
sf::IpAddress ip(ipAddress);
sf::TcpSocket *socket = new sf::TcpSocket;
sf::Mutex mutex;
bool done = false;
if( socket->connect(ip, 2000) == 0 )
{
cout<<"Enter online id : ";
std::getline(cin, id);
sf::Packet packet;
packet<<id;
socket->send(packet);
sf::Thread thread( &checkRequest, socket);
thread.launch();
mutex.lock();
sf::Thread thread2( &menu, socket);
thread2.launch();
mutex.unlock();
}
else
{
cout<<"Couldn't connect to the server try again later"<<endl;
}
return 0;
}
sometimes both threads work correctly but sometimes they don't work properly. i don't face any error. is there any problem regarding Operating system?