I'm attempting right now to make it so when I close my window, the thread stops by passing in a boolean (running) variable to my thread. However...when I close my window the thread does not appear to stop until I close the console window. The main window (RenderWindow) closes as expected, but the console window does not....Not sure what to do here.
/************************************************************
SERVER
************************************************************/
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
void netThread(void *userData){
bool running = *(bool*) userData;
while(running)
cout << running << endl;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
bool running = true;
sf::Thread thread(&netThread, &running);
thread.launch();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed){
running = false;
window.close();
}
}
window.clear();
window.display();
}
running = false;
return 0;
}