{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/23584528","id":23584528,"diff_hunk":"@@ -206,6 +207,29 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread {\n     native\n }\n \n+#[cfg(any(target_os = \"linux\", target_os = \"android\"))]\n+pub unsafe fn set_name(name: &str) {\n+    // Using prctl() rather than pthread_setname_np(),\n+    // because pthread_setname_np() wasn't added until glibc 2.12\n+    // PR_SET_NAME since Linux 2.6.9\n+    let cname = CString::from_slice(name.as_bytes());\n+    prctl(15i32 /* = PR_SET_NAME */, cname.as_ptr() as u64, 0u64, 0u64, 0u64);\n+}\n+\n+#[cfg(any(target_os = \"freebsd\", target_os = \"dragonfly\"))]\n+pub unsafe fn set_name(name: &str) {\n+    // pthread_set_name_np() since almost forever on all BSDs\n+    let cname = CString::from_slice(name.as_bytes());\n+    pthread_set_name_np(pthread_self(), cname.as_ptr());\n+}\n+\n+#[cfg(target_os = \"macos\")]","path":"src/libstd/sys/unix/thread.rs","position":28,"original_position":28,"commit_id":"ec4981ece86769c768d61a914093a7a39192522c","original_commit_id":"ec4981ece86769c768d61a914093a7a39192522c","user":{"login":"vojtechkral","id":424891,"avatar_url":"https://avatars.githubusercontent.com/u/424891?v=3","gravatar_id":"","url":"https://api.github.com/users/vojtechkral","html_url":"https://github.com/vojtechkral","followers_url":"https://api.github.com/users/vojtechkral/followers","following_url":"https://api.github.com/users/vojtechkral/following{/other_user}","gists_url":"https://api.github.com/users/vojtechkral/gists{/gist_id}","starred_url":"https://api.github.com/users/vojtechkral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vojtechkral/subscriptions","organizations_url":"https://api.github.com/users/vojtechkral/orgs","repos_url":"https://api.github.com/users/vojtechkral/repos","events_url":"https://api.github.com/users/vojtechkral/events{/privacy}","received_events_url":"https://api.github.com/users/vojtechkral/received_events","type":"User","site_admin":false},"body":"@huonw It would make sense since the two OSes share the same posix base, but I can't find a direct confirmation... There is a `target_os` for iOS?","created_at":"2015-01-27T03:06:43Z","updated_at":"2015-01-27T03:06:43Z","html_url":"https://github.com/rust-lang/rust/pull/21678#discussion_r23584528","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/21678","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/23584528"},"html":{"href":"https://github.com/rust-lang/rust/pull/21678#discussion_r23584528"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/21678"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/21678","id":28079963,"html_url":"https://github.com/rust-lang/rust/pull/21678","diff_url":"https://github.com/rust-lang/rust/pull/21678.diff","patch_url":"https://github.com/rust-lang/rust/pull/21678.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/21678","number":21678,"state":"open","locked":false,"title":"Thread native name setting","user":{"login":"vojtechkral","id":424891,"avatar_url":"https://avatars.githubusercontent.com/u/424891?v=3","gravatar_id":"","url":"https://api.github.com/users/vojtechkral","html_url":"https://github.com/vojtechkral","followers_url":"https://api.github.com/users/vojtechkral/followers","following_url":"https://api.github.com/users/vojtechkral/following{/other_user}","gists_url":"https://api.github.com/users/vojtechkral/gists{/gist_id}","starred_url":"https://api.github.com/users/vojtechkral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vojtechkral/subscriptions","organizations_url":"https://api.github.com/users/vojtechkral/orgs","repos_url":"https://api.github.com/users/vojtechkral/repos","events_url":"https://api.github.com/users/vojtechkral/events{/privacy}","received_events_url":"https://api.github.com/users/vojtechkral/received_events","type":"User","site_admin":false},"body":"Fixes #10302\r\n\r\nI really am not sure I'm doing this right, so here goes nothing...\r\n\r\nAlso testing this isn't easy. I don't have any other *nix boxes besides a Linux one.\r\n\r\nTest code:\r\n\r\n```rust\r\nuse std::thread;\r\nuse std::io::timer::sleep;\r\nuse std::time::duration::Duration;\r\n\r\nfn make_thread<'a>(i: i64) -> thread::JoinGuard<'a, ()>\r\n{\r\n\tthread::Builder::new().name(format!(\"MyThread{}\", i).to_string()).scoped(move ||\r\n\t{\r\n\t\tprintln!(\"Start: {}\", i);\r\n\t\tsleep(Duration::seconds(i));\r\n\t\tprintln!(\"End: {}\", i);\r\n\t})\r\n}\r\n\r\nfn main()\r\n{\r\n\tlet mut guards = vec![make_thread(3)];\r\n\r\n\tfor i in 4i64..16\r\n\t{\r\n\t\tguards.push(make_thread(i));\r\n\t}\r\n}\r\n```\r\n\r\nGDB output on my machine:\r\n\r\n```\r\n(gdb) info threads\r\n  Id   Target Id         Frame \r\n  15   Thread 0x7fdfbb35f700 (LWP 23575) \"MyThread3\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  14   Thread 0x7fdfba7ff700 (LWP 23576) \"MyThread4\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  13   Thread 0x7fdfba5fe700 (LWP 23577) \"MyThread5\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  12   Thread 0x7fdfba3fd700 (LWP 23578) \"MyThread6\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  11   Thread 0x7fdfb8dfe700 (LWP 23580) \"MyThread4\" 0x00007fdfbb746193 in select () from /usr/lib/libc.so.6\r\n  10   Thread 0x7fdfb8fff700 (LWP 23579) \"MyThread7\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  9    Thread 0x7fdfb8bfd700 (LWP 23581) \"MyThread8\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  8    Thread 0x7fdfb3fff700 (LWP 23582) \"MyThread9\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  7    Thread 0x7fdfb3dfe700 (LWP 23583) \"MyThread10\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  6    Thread 0x7fdfb3bfd700 (LWP 23584) \"MyThread11\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  5    Thread 0x7fdfb2bff700 (LWP 23585) \"MyThread12\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  4    Thread 0x7fdfb29fe700 (LWP 23586) \"MyThread13\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  3    Thread 0x7fdfb27fd700 (LWP 23587) \"MyThread14\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n  2    Thread 0x7fdfb1bff700 (LWP 23588) \"MyThread15\" 0x00007fdfbbe35a8d in nanosleep () from /usr/lib/libpthread.so.0\r\n* 1    Thread 0x7fdfbc411800 (LWP 23574) \"threads\" 0x00007fdfbbe2e505 in pthread_join () from /usr/lib/libpthread.so.0\r\n```\r\n(I'm not sure why one of the threads is duplicated, but it does that without my patch too...)\r\n","created_at":"2015-01-27T02:53:39Z","updated_at":"2015-01-27T03:06:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e749ca27a0f56166b7f85a6e9104f68c12f989df","assignee":{"login":"pcwalton","id":157897,"avatar_url":"https://avatars.githubusercontent.com/u/157897?v=3","gravatar_id":"","url":"https://api.github.com/users/pcwalton","html_url":"https://github.com/pcwalton","followers_url":"https://api.github.com/users/pcwalton/followers","following_url":"https://api.github.com/users/pcwalton/following{/other_user}","gists_url":"https://api.github.com/users/pcwalton/gists{/gist_id}","starred_url":"https://api.github.com/users/pcwalton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcwalton/subscriptions","organizations_url":"https://api.github.com/users/pcwalton/orgs","repos_url":"https://api.github.com/users/pcwalton/repos","events_url":"https://api.github.com/users/pcwalton/events{/privacy}","received_events_url":"https://api.github.com/users/pcwalton/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/21678/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/21678/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/21678/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/ec4981ece86769c768d61a914093a7a39192522c","head":{"label":"vojtechkral:threads-native-names","ref":"threads-native-names","sha":"ec4981ece86769c768d61a914093a7a39192522c","user":{"login":"vojtechkral","id":424891,"avatar_url":"https://avatars.githubusercontent.com/u/424891?v=3","gravatar_id":"","url":"https://api.github.com/users/vojtechkral","html_url":"https://github.com/vojtechkral","followers_url":"https://api.github.com/users/vojtechkral/followers","following_url":"https://api.github.com/users/vojtechkral/following{/other_user}","gists_url":"https://api.github.com/users/vojtechkral/gists{/gist_id}","starred_url":"https://api.github.com/users/vojtechkral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vojtechkral/subscriptions","organizations_url":"https://api.github.com/users/vojtechkral/orgs","repos_url":"https://api.github.com/users/vojtechkral/repos","events_url":"https://api.github.com/users/vojtechkral/events{/privacy}","received_events_url":"https://api.github.com/users/vojtechkral/received_events","type":"User","site_admin":false},"repo":{"id":26879929,"name":"rust","full_name":"vojtechkral/rust","owner":{"login":"vojtechkral","id":424891,"avatar_url":"https://avatars.githubusercontent.com/u/424891?v=3","gravatar_id":"","url":"https://api.github.com/users/vojtechkral","html_url":"https://github.com/vojtechkral","followers_url":"https://api.github.com/users/vojtechkral/followers","following_url":"https://api.github.com/users/vojtechkral/following{/other_user}","gists_url":"https://api.github.com/users/vojtechkral/gists{/gist_id}","starred_url":"https://api.github.com/users/vojtechkral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vojtechkral/subscriptions","organizations_url":"https://api.github.com/users/vojtechkral/orgs","repos_url":"https://api.github.com/users/vojtechkral/repos","events_url":"https://api.github.com/users/vojtechkral/events{/privacy}","received_events_url":"https://api.github.com/users/vojtechkral/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vojtechkral/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/vojtechkral/rust","forks_url":"https://api.github.com/repos/vojtechkral/rust/forks","keys_url":"https://api.github.com/repos/vojtechkral/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vojtechkral/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vojtechkral/rust/teams","hooks_url":"https://api.github.com/repos/vojtechkral/rust/hooks","issue_events_url":"https://api.github.com/repos/vojtechkral/rust/issues/events{/number}","events_url":"https://api.github.com/repos/vojtechkral/rust/events","assignees_url":"https://api.github.com/repos/vojtechkral/rust/assignees{/user}","branches_url":"https://api.github.com/repos/vojtechkral/rust/branches{/branch}","tags_url":"https://api.github.com/repos/vojtechkral/rust/tags","blobs_url":"https://api.github.com/repos/vojtechkral/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vojtechkral/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vojtechkral/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/vojtechkral/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vojtechkral/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/vojtechkral/rust/languages","stargazers_url":"https://api.github.com/repos/vojtechkral/rust/stargazers","contributors_url":"https://api.github.com/repos/vojtechkral/rust/contributors","subscribers_url":"https://api.github.com/repos/vojtechkral/rust/subscribers","subscription_url":"https://api.github.com/repos/vojtechkral/rust/subscription","commits_url":"https://api.github.com/repos/vojtechkral/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/vojtechkral/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/vojtechkral/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/vojtechkral/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/vojtechkral/rust/contents/{+path}","compare_url":"https://api.github.com/repos/vojtechkral/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vojtechkral/rust/merges","archive_url":"https://api.github.com/repos/vojtechkral/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vojtechkral/rust/downloads","issues_url":"https://api.github.com/repos/vojtechkral/rust/issues{/number}","pulls_url":"https://api.github.com/repos/vojtechkral/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/vojtechkral/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/vojtechkral/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vojtechkral/rust/labels{/name}","releases_url":"https://api.github.com/repos/vojtechkral/rust/releases{/id}","created_at":"2014-11-19T20:19:53Z","updated_at":"2015-01-27T02:39:25Z","pushed_at":"2015-01-27T02:46:39Z","git_url":"git://github.com/vojtechkral/rust.git","ssh_url":"git@github.com:vojtechkral/rust.git","clone_url":"https://github.com/vojtechkral/rust.git","svn_url":"https://github.com/vojtechkral/rust","homepage":"http://www.rust-lang.org","size":219370,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"a637365b10c175e23af40171af1724d5474cb303","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rust","description":"a safe, concurrent, practical language","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","created_at":"2010-06-16T20:39:03Z","updated_at":"2015-01-27T03:04:45Z","pushed_at":"2015-01-27T02:46:10Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"http://www.rust-lang.org","size":449871,"stargazers_count":9064,"watchers_count":9064,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1750,"mirror_url":null,"open_issues_count":2148,"forks":1750,"open_issues":2148,"watchers":9064,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/21678"},"html":{"href":"https://github.com/rust-lang/rust/pull/21678"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/21678"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/21678/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/21678/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/21678/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/ec4981ece86769c768d61a914093a7a39192522c"}}}}