diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 7b667416b1714..8e1f169b5cdcc 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -25,6 +25,8 @@ use path::BytesContainer; use ptr; use str; use sys::fs::FileDesc; +use sync::{StaticMutex, MUTEX_INIT}; + use sys::fs; use sys::{self, retry, c, wouldblock, set_nonblocking, ms_to_timeval, timer}; use sys_common::helper_thread::Helper; @@ -32,6 +34,10 @@ use sys_common::{AsInner, mkerr_libc, timeout}; pub use sys_common::ProcessConfig; +// `CreateProcess` is racy! +// http://support.microsoft.com/kb/315939 +static CREATE_PROCESS_LOCK: StaticMutex = MUTEX_INIT; + /// A value representing a child process. /// /// The lifetime of this value is linked to the lifetime of the actual @@ -224,6 +230,7 @@ impl Process { with_dirp(cfg.cwd(), |dirp| { let mut cmd_str: Vec = cmd_str.utf16_units().collect(); cmd_str.push(0); + let _lock = CREATE_PROCESS_LOCK.lock().unwrap(); let created = CreateProcessW(ptr::null(), cmd_str.as_mut_ptr(), ptr::null_mut(),