Added mutex lock for thread creation