Proper joining of threads in main thread.