Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize std::thread #20615

Merged
merged 2 commits into from
Jan 7, 2015
Merged

Stabilize std::thread #20615

merged 2 commits into from
Jan 7, 2015

Commits on Jan 6, 2015

  1. Stabilize std::thread

    This commit takes a first pass at stabilizing `std::thread`:
    
    * It removes the `detach` method in favor of two constructors -- `spawn`
      for detached threads, `scoped` for "scoped" (i.e., must-join)
      threads. This addresses some of the surprise/frustrating debug
      sessions with the previous API, in which `spawn` produced a guard that
      on destruction joined the thread (unless `detach` was called).
    
      The reason to have the division in part is that `Send` will soon not
      imply `'static`, which means that `scoped` thread creation can take a
      closure over *shared stack data* of the parent thread. On the other
      hand, this means that the parent must not pop the relevant stack
      frames while the child thread is running. The `JoinGuard` is used to
      prevent this from happening by joining on drop (if you have not
      already explicitly `join`ed.) The APIs around `scoped` are
      future-proofed for the `Send` changes by taking an additional lifetime
      parameter. With the current definition of `Send`, this is forced to be
      `'static`, but when `Send` changes these APIs will gain their full
      flexibility immediately.
    
      Threads that are `spawn`ed, on the other hand, are detached from the
      start and do not yield an RAII guard.
    
      The hope is that, by making `scoped` an explicit opt-in with a very
      suggestive name, it will be drastically less likely to be caught by a
      surprising deadlock due to an implicit join at the end of a scope.
    
    * The module itself is marked stable.
    
    * Existing methods other than `spawn` and `scoped` are marked stable.
    
    The migration path is:
    
    ```rust
    Thread::spawn(f).detached()
    ```
    
    becomes
    
    ```rust
    Thread::spawn(f)
    ```
    
    while
    
    ```rust
    let res = Thread::spawn(f);
    res.join()
    ```
    
    becomes
    
    ```rust
    let res = Thread::scoped(f);
    res.join()
    ```
    
    [breaking-change]
    aturon committed Jan 6, 2015
    Configuration menu
    Copy the full SHA
    f67b81e View commit details
    Browse the repository at this point in the history
  2. Fallout from stabilization

    aturon committed Jan 6, 2015
    Configuration menu
    Copy the full SHA
    caca9b2 View commit details
    Browse the repository at this point in the history