Skip to content

The example in the concurrency guide is incorrect #20844

Closed

Description

@reem

The offending example is:

use std::thread::Thread;

fn main() {
    for _ in 0..10 {
        Thread::spawn(|| {
            println!("Hello World!");
        });
    }
}

With the new detaching thread semantics, this is incorrect since main can exit before all the detached threads have printed.

Activity

  1. steveklabnik commented on Jan 10, 2015

    @steveklabnik
    Contributor

    I think that this was in the intro as well.

  2. added a commit that references this issue on Jan 15, 2015
    6155ce5
  3. added a commit that references this issue on Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions