need help with boost multi-threading

The program runs fine. I type in the ip adress i want to connect to and connect to the server fine, but after about 5 seconds i get this break-continue box message
1
2
3
unhandled exception at ...:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<
boost::thread_resource_error> > at memory location 0x003ff964..



Here is the relevant client code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//in main()
while( Connected )
	{
		//Thread for sending messages
		tgroup.create_thread( boost::bind(&SendMessage) );
		
		//Thread for receiving messages
		tgroup.create_thread( boost::bind(&ReceiveMessage) );
	}

	// Close the socket
	socket.disconnect();

	//main thread waits for all threads to join back together
	tgroup.join_all();

	return 0;
}

//Thread functions
void SendMessage()
{
	// Let the user write a message
	std::string SendMessage;
	std::getline(std::cin, SendMessage);

	// Send it to the server
	sf::Packet SendPacket;
	SendPacket << SendMessage;
	std::cout<<"Sending message : "<<SendMessage<<std::endl;
	if(socket.send(SendPacket) != sf::Socket::Done)
		std::cout<<"Error sending message"<<std::endl;
}

void ReceiveMessage()
{
	// Receive from the server
	sf::Packet ReceivePacket;
	std::string ReceiveMessage;
	if(socket.receive(ReceivePacket) == sf::Socket::Done)
	{
		ReceivePacket >> ReceiveMessage;
		std::cout << "Received Message : "<<ReceiveMessage << std::endl;
	}
}
1
2
while( Connected )
	{

What is "Connected"? How long does this loop run? Put a test output statement in it.
Connected is always true. It was old code that i just kept, but Connected is declared true right before the while loop starts.

However, i added a start and end message to the beginning and end of both thread functions, and found something interesting.

This is the output:
1
2
3
4
5
6
SendMessage StartReceiveMessage Start
ReceiveMessage Start
SendMessage Start
SendMessage Start
ReceiveMessage Start
// etc 


The interesting thing is that "SendMessage End" nor "ReceiveMessage End" were ever outputted. It seems like the threads just keep restarting. Im really new to threads so I'm going to need some help explaining this behavior.
Topic archived. No new replies allowed.