Skip to content

Commit

Permalink
Rollup merge of rust-lang#44651 - bluss:document-thread-name-no-nuls,…
Browse files Browse the repository at this point in the history
… r=steveklabnik

Document thread builder panics for nul bytes in thread names

This seems to have been undocumented. Mention this where the name is set
(Builder::name) and where the panic could happen (Builder::spawn).

Thread::new is private and I think the builder is the only user where
this matters. A short comment was added to "document" Thread::new too.
  • Loading branch information
alexcrichton authored Sep 18, 2017
2 parents fa9dd27 + 7859c9e commit d5b0cbb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ impl Builder {
/// Names the thread-to-be. Currently the name is used for identification
/// only in panic messages.
///
/// The name must not contain null bytes (`\0`).
///
/// For more information about named threads, see
/// [this module-level documentation][naming-threads].
///
Expand Down Expand Up @@ -355,6 +357,10 @@ impl Builder {
/// [`io::Result`]: ../../std/io/type.Result.html
/// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
///
/// # Panics
///
/// Panics if a thread name was set and it contained null bytes.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -941,6 +947,7 @@ pub struct Thread {

impl Thread {
// Used only internally to construct a thread object without spawning
// Panics if the name contains nuls.
pub(crate) fn new(name: Option<String>) -> Thread {
let cname = name.map(|n| {
CString::new(n).expect("thread name may not contain interior null bytes")
Expand Down

0 comments on commit d5b0cbb

Please sign in to comment.