Merge "Fix race condition in thread creation"