{"action":"created","comment":{"url":"https://api.github.com/repos/libuv/libuv/pulls/comments/33678010","id":33678010,"diff_hunk":"@@ -191,7 +191,13 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {\n \n \n uv_thread_t uv_thread_self(void) {\n-  return (uv_thread_t) uv_key_get(&uv__current_thread_key);\n+  void* self;\n+  uv_once(&uv__current_thread_init_guard, uv__init_current_thread_key);\n+  self = uv_key_get(&uv__current_thread_key);\n+  if (self == NULL)\n+      /* This thread wasn't created with uv_thread_create. */\n+      self = GetCurrentThread();","path":"src/win/thread.c","position":10,"original_position":10,"commit_id":"46178c7f80853d554dca22f162fab0a74e3a8348","original_commit_id":"46178c7f80853d554dca22f162fab0a74e3a8348","user":{"login":"orangemocha","id":1625870,"avatar_url":"https://avatars.githubusercontent.com/u/1625870?v=3","gravatar_id":"","url":"https://api.github.com/users/orangemocha","html_url":"https://github.com/orangemocha","followers_url":"https://api.github.com/users/orangemocha/followers","following_url":"https://api.github.com/users/orangemocha/following{/other_user}","gists_url":"https://api.github.com/users/orangemocha/gists{/gist_id}","starred_url":"https://api.github.com/users/orangemocha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orangemocha/subscriptions","organizations_url":"https://api.github.com/users/orangemocha/orgs","repos_url":"https://api.github.com/users/orangemocha/repos","events_url":"https://api.github.com/users/orangemocha/events{/privacy}","received_events_url":"https://api.github.com/users/orangemocha/received_events","type":"User","site_admin":false},"body":"Yes, it would be NULL for any thread not created by libuv (including the main thread). My point is that GetCurrentThread() returns a constant (I think it's -2), so NULL is just as good. \r\n\r\nIn order to get a unique per-thread HANDLE for those threads that were not created by libuv, we would have to call DuplicateHandle on that pseudo-handle, but then we would also have to make sure we close those handles when the thread exits. AFAIK, no one has complained so far about libuv returning the same value for all threads not created by uv_thread_create().","created_at":"2015-07-01T13:33:46Z","updated_at":"2015-07-01T13:33:46Z","html_url":"https://github.com/libuv/libuv/pull/418#discussion_r33678010","pull_request_url":"https://api.github.com/repos/libuv/libuv/pulls/418","_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments/33678010"},"html":{"href":"https://github.com/libuv/libuv/pull/418#discussion_r33678010"},"pull_request":{"href":"https://api.github.com/repos/libuv/libuv/pulls/418"}}},"pull_request":{"url":"https://api.github.com/repos/libuv/libuv/pulls/418","id":38956216,"html_url":"https://github.com/libuv/libuv/pull/418","diff_url":"https://github.com/libuv/libuv/pull/418.diff","patch_url":"https://github.com/libuv/libuv/pull/418.patch","issue_url":"https://api.github.com/repos/libuv/libuv/issues/418","number":418,"state":"open","locked":false,"title":"win: fix returning thread id in uv_thread_self","user":{"login":"saghul","id":317464,"avatar_url":"https://avatars.githubusercontent.com/u/317464?v=3","gravatar_id":"","url":"https://api.github.com/users/saghul","html_url":"https://github.com/saghul","followers_url":"https://api.github.com/users/saghul/followers","following_url":"https://api.github.com/users/saghul/following{/other_user}","gists_url":"https://api.github.com/users/saghul/gists{/gist_id}","starred_url":"https://api.github.com/users/saghul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghul/subscriptions","organizations_url":"https://api.github.com/users/saghul/orgs","repos_url":"https://api.github.com/users/saghul/repos","events_url":"https://api.github.com/users/saghul/events{/privacy}","received_events_url":"https://api.github.com/users/saghul/received_events","type":"User","site_admin":false},"body":"The main thread does not have the thread id TLS created.\r\n\r\nFixes: https://github.com/joyent/node/issues/25602\r\n\r\nR=@piscisaureus, @orangemocha ","created_at":"2015-07-01T07:47:53Z","updated_at":"2015-07-01T13:33:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"48ced36223551d62ac995837263af52efd8fc311","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/libuv/libuv/pulls/418/commits","review_comments_url":"https://api.github.com/repos/libuv/libuv/pulls/418/comments","review_comment_url":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/418/comments","statuses_url":"https://api.github.com/repos/libuv/libuv/statuses/46178c7f80853d554dca22f162fab0a74e3a8348","head":{"label":"saghul:win-uv_thread_self","ref":"win-uv_thread_self","sha":"46178c7f80853d554dca22f162fab0a74e3a8348","user":{"login":"saghul","id":317464,"avatar_url":"https://avatars.githubusercontent.com/u/317464?v=3","gravatar_id":"","url":"https://api.github.com/users/saghul","html_url":"https://github.com/saghul","followers_url":"https://api.github.com/users/saghul/followers","following_url":"https://api.github.com/users/saghul/following{/other_user}","gists_url":"https://api.github.com/users/saghul/gists{/gist_id}","starred_url":"https://api.github.com/users/saghul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghul/subscriptions","organizations_url":"https://api.github.com/users/saghul/orgs","repos_url":"https://api.github.com/users/saghul/repos","events_url":"https://api.github.com/users/saghul/events{/privacy}","received_events_url":"https://api.github.com/users/saghul/received_events","type":"User","site_admin":false},"repo":{"id":29688883,"name":"libuv","full_name":"saghul/libuv","owner":{"login":"saghul","id":317464,"avatar_url":"https://avatars.githubusercontent.com/u/317464?v=3","gravatar_id":"","url":"https://api.github.com/users/saghul","html_url":"https://github.com/saghul","followers_url":"https://api.github.com/users/saghul/followers","following_url":"https://api.github.com/users/saghul/following{/other_user}","gists_url":"https://api.github.com/users/saghul/gists{/gist_id}","starred_url":"https://api.github.com/users/saghul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghul/subscriptions","organizations_url":"https://api.github.com/users/saghul/orgs","repos_url":"https://api.github.com/users/saghul/repos","events_url":"https://api.github.com/users/saghul/events{/privacy}","received_events_url":"https://api.github.com/users/saghul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/saghul/libuv","description":"Cross-platform asychronous I/O","fork":true,"url":"https://api.github.com/repos/saghul/libuv","forks_url":"https://api.github.com/repos/saghul/libuv/forks","keys_url":"https://api.github.com/repos/saghul/libuv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saghul/libuv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saghul/libuv/teams","hooks_url":"https://api.github.com/repos/saghul/libuv/hooks","issue_events_url":"https://api.github.com/repos/saghul/libuv/issues/events{/number}","events_url":"https://api.github.com/repos/saghul/libuv/events","assignees_url":"https://api.github.com/repos/saghul/libuv/assignees{/user}","branches_url":"https://api.github.com/repos/saghul/libuv/branches{/branch}","tags_url":"https://api.github.com/repos/saghul/libuv/tags","blobs_url":"https://api.github.com/repos/saghul/libuv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saghul/libuv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saghul/libuv/git/refs{/sha}","trees_url":"https://api.github.com/repos/saghul/libuv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saghul/libuv/statuses/{sha}","languages_url":"https://api.github.com/repos/saghul/libuv/languages","stargazers_url":"https://api.github.com/repos/saghul/libuv/stargazers","contributors_url":"https://api.github.com/repos/saghul/libuv/contributors","subscribers_url":"https://api.github.com/repos/saghul/libuv/subscribers","subscription_url":"https://api.github.com/repos/saghul/libuv/subscription","commits_url":"https://api.github.com/repos/saghul/libuv/commits{/sha}","git_commits_url":"https://api.github.com/repos/saghul/libuv/git/commits{/sha}","comments_url":"https://api.github.com/repos/saghul/libuv/comments{/number}","issue_comment_url":"https://api.github.com/repos/saghul/libuv/issues/comments{/number}","contents_url":"https://api.github.com/repos/saghul/libuv/contents/{+path}","compare_url":"https://api.github.com/repos/saghul/libuv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saghul/libuv/merges","archive_url":"https://api.github.com/repos/saghul/libuv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saghul/libuv/downloads","issues_url":"https://api.github.com/repos/saghul/libuv/issues{/number}","pulls_url":"https://api.github.com/repos/saghul/libuv/pulls{/number}","milestones_url":"https://api.github.com/repos/saghul/libuv/milestones{/number}","notifications_url":"https://api.github.com/repos/saghul/libuv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saghul/libuv/labels{/name}","releases_url":"https://api.github.com/repos/saghul/libuv/releases{/id}","created_at":"2015-01-22T16:45:52Z","updated_at":"2015-01-22T16:45:54Z","pushed_at":"2015-07-01T07:47:26Z","git_url":"git://github.com/saghul/libuv.git","ssh_url":"git@github.com:saghul/libuv.git","clone_url":"https://github.com/saghul/libuv.git","svn_url":"https://github.com/saghul/libuv","homepage":"http://libuv.org/","size":12339,"stargazers_count":0,"watchers_count":0,"language":"C","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":"v1.x"}},"base":{"label":"libuv:v1.x","ref":"v1.x","sha":"7980f1359dd16e8ded20a80e934deaf269d85f03","user":{"login":"libuv","id":4030929,"avatar_url":"https://avatars.githubusercontent.com/u/4030929?v=3","gravatar_id":"","url":"https://api.github.com/users/libuv","html_url":"https://github.com/libuv","followers_url":"https://api.github.com/users/libuv/followers","following_url":"https://api.github.com/users/libuv/following{/other_user}","gists_url":"https://api.github.com/users/libuv/gists{/gist_id}","starred_url":"https://api.github.com/users/libuv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libuv/subscriptions","organizations_url":"https://api.github.com/users/libuv/orgs","repos_url":"https://api.github.com/users/libuv/repos","events_url":"https://api.github.com/users/libuv/events{/privacy}","received_events_url":"https://api.github.com/users/libuv/received_events","type":"Organization","site_admin":false},"repo":{"id":14812739,"name":"libuv","full_name":"libuv/libuv","owner":{"login":"libuv","id":4030929,"avatar_url":"https://avatars.githubusercontent.com/u/4030929?v=3","gravatar_id":"","url":"https://api.github.com/users/libuv","html_url":"https://github.com/libuv","followers_url":"https://api.github.com/users/libuv/followers","following_url":"https://api.github.com/users/libuv/following{/other_user}","gists_url":"https://api.github.com/users/libuv/gists{/gist_id}","starred_url":"https://api.github.com/users/libuv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libuv/subscriptions","organizations_url":"https://api.github.com/users/libuv/orgs","repos_url":"https://api.github.com/users/libuv/repos","events_url":"https://api.github.com/users/libuv/events{/privacy}","received_events_url":"https://api.github.com/users/libuv/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libuv/libuv","description":"Cross-platform asychronous I/O","fork":false,"url":"https://api.github.com/repos/libuv/libuv","forks_url":"https://api.github.com/repos/libuv/libuv/forks","keys_url":"https://api.github.com/repos/libuv/libuv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libuv/libuv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libuv/libuv/teams","hooks_url":"https://api.github.com/repos/libuv/libuv/hooks","issue_events_url":"https://api.github.com/repos/libuv/libuv/issues/events{/number}","events_url":"https://api.github.com/repos/libuv/libuv/events","assignees_url":"https://api.github.com/repos/libuv/libuv/assignees{/user}","branches_url":"https://api.github.com/repos/libuv/libuv/branches{/branch}","tags_url":"https://api.github.com/repos/libuv/libuv/tags","blobs_url":"https://api.github.com/repos/libuv/libuv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libuv/libuv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libuv/libuv/git/refs{/sha}","trees_url":"https://api.github.com/repos/libuv/libuv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libuv/libuv/statuses/{sha}","languages_url":"https://api.github.com/repos/libuv/libuv/languages","stargazers_url":"https://api.github.com/repos/libuv/libuv/stargazers","contributors_url":"https://api.github.com/repos/libuv/libuv/contributors","subscribers_url":"https://api.github.com/repos/libuv/libuv/subscribers","subscription_url":"https://api.github.com/repos/libuv/libuv/subscription","commits_url":"https://api.github.com/repos/libuv/libuv/commits{/sha}","git_commits_url":"https://api.github.com/repos/libuv/libuv/git/commits{/sha}","comments_url":"https://api.github.com/repos/libuv/libuv/comments{/number}","issue_comment_url":"https://api.github.com/repos/libuv/libuv/issues/comments{/number}","contents_url":"https://api.github.com/repos/libuv/libuv/contents/{+path}","compare_url":"https://api.github.com/repos/libuv/libuv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libuv/libuv/merges","archive_url":"https://api.github.com/repos/libuv/libuv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libuv/libuv/downloads","issues_url":"https://api.github.com/repos/libuv/libuv/issues{/number}","pulls_url":"https://api.github.com/repos/libuv/libuv/pulls{/number}","milestones_url":"https://api.github.com/repos/libuv/libuv/milestones{/number}","notifications_url":"https://api.github.com/repos/libuv/libuv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libuv/libuv/labels{/name}","releases_url":"https://api.github.com/repos/libuv/libuv/releases{/id}","created_at":"2013-11-30T00:29:56Z","updated_at":"2015-07-01T11:02:27Z","pushed_at":"2015-07-01T12:17:48Z","git_url":"git://github.com/libuv/libuv.git","ssh_url":"git@github.com:libuv/libuv.git","clone_url":"https://github.com/libuv/libuv.git","svn_url":"https://github.com/libuv/libuv","homepage":"http://libuv.org/","size":19124,"stargazers_count":1782,"watchers_count":1782,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":244,"mirror_url":null,"open_issues_count":82,"forks":244,"open_issues":82,"watchers":1782,"default_branch":"v1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/418"},"html":{"href":"https://github.com/libuv/libuv/pull/418"},"issue":{"href":"https://api.github.com/repos/libuv/libuv/issues/418"},"comments":{"href":"https://api.github.com/repos/libuv/libuv/issues/418/comments"},"review_comments":{"href":"https://api.github.com/repos/libuv/libuv/pulls/418/comments"},"review_comment":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libuv/libuv/pulls/418/commits"},"statuses":{"href":"https://api.github.com/repos/libuv/libuv/statuses/46178c7f80853d554dca22f162fab0a74e3a8348"}}}}