I think I see what's wrong. The thread goes out of scope, so it is closed.

Maybe I am thinking wrong, but try making the thread object a class object instead of a function object.