Fix data race by using an atomic int.
Fix the mDelay code; fix the cause of one of the crashes switching tabs.