Im using visual studio 2012 and C ++ 11. I don't understand why this is not working:
void client_loop(bool &run) { while ( run ); } int main() { bool running = true; std::thread t(&client_loop,std::ref(running)); running = false ; t.join(); }
In this case, the loop of thread t never ends, but I explicability is set to running false . run and running have the same location. I tried setting running as one global variable, but nothing happens. I also tried to pass the value of the pointer, but nothing.
Threads use the same heap. I really do not understand. Can anybody help me?
source share