{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/20615","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/20615/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/20615/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/20615/events","html_url":"https://github.com/rust-lang/rust/pull/20615","id":53484793,"number":20615,"title":"Stabilize std::thread","user":{"login":"aturon","id":709807,"avatar_url":"https://avatars.githubusercontent.com/u/709807?v=3","gravatar_id":"","url":"https://api.github.com/users/aturon","html_url":"https://github.com/aturon","followers_url":"https://api.github.com/users/aturon/followers","following_url":"https://api.github.com/users/aturon/following{/other_user}","gists_url":"https://api.github.com/users/aturon/gists{/gist_id}","starred_url":"https://api.github.com/users/aturon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aturon/subscriptions","organizations_url":"https://api.github.com/users/aturon/orgs","repos_url":"https://api.github.com/users/aturon/repos","events_url":"https://api.github.com/users/aturon/events{/privacy}","received_events_url":"https://api.github.com/users/aturon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"comments":13,"created_at":"2015-01-06T06:13:32Z","updated_at":"2015-01-06T16:58:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/20615","html_url":"https://github.com/rust-lang/rust/pull/20615","diff_url":"https://github.com/rust-lang/rust/pull/20615.diff","patch_url":"https://github.com/rust-lang/rust/pull/20615.patch"},"body":"This commit takes a first pass at stabilizing `std::thread`:\r\n\r\n* It removes the `detach` method in favor of two constructors -- `spawn`\r\n  for detached threads, `scoped` for \"scoped\" (i.e., must-join)\r\n  threads. This addresses some of the surprise/frustrating debug\r\n  sessions with the previous API, in which `spawn` produced a guard that\r\n  on destruction joined the thread (unless `detach` was called).\r\n\r\n  The reason to have the division in part is that `Send` will soon not\r\n  imply `'static`, which means that `scoped` thread creation can take a\r\n  closure over *shared stack data* of the parent thread. On the other\r\n  hand, this means that the parent must not pop the relevant stack\r\n  frames while the child thread is running. The `JoinGuard` is used to\r\n  prevent this from happening by joining on drop (if you have not\r\n  already explicitly `join`ed.) The APIs around `scoped` are\r\n  future-proofed for the `Send` changes by taking an additional lifetime\r\n  parameter. With the current definition of `Send`, this is forced to be\r\n  `'static`, but when `Send` changes these APIs will gain their full\r\n  flexibility immediately.\r\n\r\n  Threads that are `spawn`ed, on the other hand, are detached from the\r\n  start and do not yield an RAII guard.\r\n\r\n  The hope is that, by making `scoped` an explicit opt-in with a very\r\n  suggestive name, it will be drastically less likely to be caught by a\r\n  surprising deadlock due to an implicit join at the end of a scope.\r\n\r\n* The module itself is marked stable.\r\n\r\n* Existing methods other than `spawn` and `scoped` are marked stable.\r\n\r\nThe migration path is:\r\n\r\n```rust\r\nThread::spawn(f).detached()\r\n```\r\n\r\nbecomes\r\n\r\n```rust\r\nThread::spawn(f)\r\n```\r\n\r\nwhile\r\n\r\n```rust\r\nlet res = Thread::spawn(f);\r\nres.join()\r\n```\r\n\r\nbecomes\r\n\r\n```rust\r\nlet res = Thread::scoped(f);\r\nres.join()\r\n```\r\n\r\n[breaking-change]"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/68893871","html_url":"https://github.com/rust-lang/rust/pull/20615#issuecomment-68893871","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/20615","id":68893871,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2015-01-06T16:58:21Z","updated_at":"2015-01-06T16:58:21Z","body":"This is a pretty conservative step, so r=me with a few nits, we've still got some room to tweak interfaces here and there as necessary."}}