Fix a race condition in languages with real threading.