Everything seems just normal to me. Couple of points:
Your code is not complete. You have three subs, but you never called InitIO, and Shutdown IO. (It is fine with main_loop, if you call InitIO, it will then call main_loop). I assume that's just copy/paste type problem. So I changed your exit statement to:
You said, the print "Exiting ..." never being printed. That is quite normal. When you called exit, you exit the process not the thread, so your main_loop sub, which is running on a detached thread, just being suddenly stoped before it was evaluated to its end. exit always stop the process, not the calling thread, doesn't matter whether the calling thread is the main thread, or a created thread.
You have a detached thread, and you didn't try anything to sync your threads, so don't expect any sync'd behavior among your threads.
If you want sync among threads, play with join, cond_wait, cond_signal, cond_broadcast.