I've got an error that I don't understand using std::thread and SFML2.1.
I didn't have this error while developping with DevCPP + TDM-GCC, but I now use Code::Blocks + TDM-GCC (Windows 7).
Basically I don't have any compilation error / warning, but I get a program not responding on thread joins if I've got a SFML RenderWindow instantiated in the main.
I tried to ask our Google friend if he new anything about that but it didn't retrieve any result that helped, appart from recompiling SFML with Code::Blocks, "just to be sure"...
Here is a very simplified piece of code on which I still get the error (I already managed to get a window with texture and text in SFML, just to but aside SFML library config problems) :
#include <SFML/Graphics.hpp>
#include <thread>
#include <iostream>
int main(int, char const**)
{
std::thread my_thread([](){
std::cout<<"toto"<<'\n';
});
my_thread.join();
//my_thread.detach();
std::cout<<"tata"<<'\n';
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
return EXIT_SUCCESS;
}
If I replace my_thread.join() with my_thread.detach(), the error goes away.
If I delete the RenderWindow instatiation, the error goes away.
Any Idea ?
Edit 2: updated build log
mingw32-g++.exe -std=c++11 -Wall -pthread -lpthread -std=c++11 -g -pthread -IC:\SFML-2.1\include -Ijabos -IC:\SFML-2.1\include -c C:\Users\frup82554\Documents\svn\jabos\jabos\main.cpp -o jabos.cb\obj\Debug\jabos\main.o
mingw32-g++.exe -LC:\SFML-2.1\lib -LC:\SFML-2.1\lib -o jabos.cb\bin\Debug\jabos.exe jabos.cb\obj\Debug\jabos\Couple.o jabos.cb\obj\Debug\jabos\Force.o jabos.cb\obj\Debug\jabos\main.o jabos.cb\obj\Debug\jabos\Masse.o jabos.cb\obj\Debug\jabos\Masse1d.o jabos.cb\obj\Debug\jabos\ThreadPool.o jabos.cb\obj\Debug\jabos\ValeurNDimension.o -lpthread -pthread -lpthread -lmingw32 -luser32 -lgdi32 -lwinmm -ldxguid -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
Output file is jabos.cb\bin\Debug\jabos.exe with size 1.62 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
-pthreadswitch is enabled. - Praetorian-pthreadswitch and still got the error. Anyway isn't this switch supposed to be about"pthread.h"? I'm using c++11 threads which are different, aren't they ? (I added the build logs as requested) - Tyrendelstd::thread). It is written:"If you work with compilers that support the new standard and its <thread> header, forget about SFML classes and use it -- it will be much better.". Since Code::Blocks compiled and ran correctly previous tests withstd::threads, I guessed it was fully compatible with C++11. - Tyrendelstd::thread. That's why you need the-pthreadswitch when compiling. The command lines above show that you're only passing-lpthreadto the link stage. Try adding-pthreadto the compilation stage also (and probably do the same for the link stage;-pthreadimplies-lpthread) - Praetorian