exit() is a very dangerous solution, because destructor's of automatic objects are not called, so any kind of object-bound resource is not properly freed.
1. use cancellation points and call cancel/join from your main thread, or
2. on threads with endless loop introduce a flag, so the loop is ended if flag is set from main thread. after setting flag call join