Run this enough times, and it should indeed hang. Try putting a loop in main() to run this 500 times. It's a timing issue; whether or not it hangs depends on how quickly the second
thread can be started.
I just compiled and ran your program and it hung the first time!