Fix Apple compiler optimization issue with the thread code

See title