Implement Sync for `process::Command on unix and vxworks
This commit is contained in:
@@ -2105,8 +2105,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_command_implements_send() {
|
fn test_command_implements_send_sync() {
|
||||||
fn take_send_type<T: Send>(_: T) {}
|
fn take_send_sync_type<T: Send + Sync>(_: T) {}
|
||||||
take_send_type(Command::new(""))
|
take_send_sync_type(Command::new(""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,13 @@ pub struct Command {
|
|||||||
stderr: Option<Stdio>,
|
stderr: Option<Stdio>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new type for argv, so that we can make it `Send`
|
// Create a new type for argv, so that we can make it `Send` and `Sync`
|
||||||
struct Argv(Vec<*const c_char>);
|
struct Argv(Vec<*const c_char>);
|
||||||
|
|
||||||
// It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args`
|
// It is safe to make `Argv` `Send` and `Sync`, because it contains
|
||||||
|
// pointers to memory owned by `Command.args`
|
||||||
unsafe impl Send for Argv {}
|
unsafe impl Send for Argv {}
|
||||||
|
unsafe impl Sync for Argv {}
|
||||||
|
|
||||||
// passed back to std::process with the pipes connected to the child, if any
|
// passed back to std::process with the pipes connected to the child, if any
|
||||||
// were requested
|
// were requested
|
||||||
|
|||||||
@@ -49,11 +49,13 @@ pub struct Command {
|
|||||||
stderr: Option<Stdio>,
|
stderr: Option<Stdio>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new type for argv, so that we can make it `Send`
|
// Create a new type for `Argv`, so that we can make it `Send` and `Sync`
|
||||||
struct Argv(Vec<*const c_char>);
|
struct Argv(Vec<*const c_char>);
|
||||||
|
|
||||||
// It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args`
|
// It is safe to make `Argv` `Send` and `Sync`, because it contains
|
||||||
|
// pointers to memory owned by `Command.args`
|
||||||
unsafe impl Send for Argv {}
|
unsafe impl Send for Argv {}
|
||||||
|
unsafe impl Sync for Argv {}
|
||||||
|
|
||||||
// passed back to std::process with the pipes connected to the child, if any
|
// passed back to std::process with the pipes connected to the child, if any
|
||||||
// were requested
|
// were requested
|
||||||
|
|||||||
Reference in New Issue
Block a user