{"action":"created","comment":{"url":"https://api.github.com/repos/libuv/libuv/pulls/comments/32579074","id":32579074,"diff_hunk":"@@ -57,104 +59,132 @@ static void uv__cancelled(struct uv__work* w) {\n }\n \n \n+/* Only call when you hold NO locks. */\n+static void do_work(struct uv__work* w) {\n+  w->work(w);\n+  uv_mutex_lock(&w->loop->wq_mutex);\n+  w->work = NULL;  /* Signal uv_cancel() that the work req is done executing. */\n+  QUEUE_INSERT_TAIL(&w->loop->wq, &w->wq);\n+  uv_async_send(&w->loop->wq_async);\n+  uv_mutex_unlock(&w->loop->wq_mutex);","path":"src/threadpool.c","position":33,"original_position":33,"commit_id":"41bddbd2bac72ce1d511ae0d22f26d98c143440d","original_commit_id":"41bddbd2bac72ce1d511ae0d22f26d98c143440d","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"body":"It probably can, but...  I wrote it this way because otherwise it's possible for the per-loop work queue to get drained between the calls to `uv_mutex_unlock()` and `uv_async_send()`, and that would wake up the event loop when there is no work available.  It's probably no big deal but I figured: why make things more complex than they already are?","created_at":"2015-06-16T22:33:43Z","updated_at":"2015-06-16T22:33:43Z","html_url":"https://github.com/libuv/libuv/pull/382#discussion_r32579074","pull_request_url":"https://api.github.com/repos/libuv/libuv/pulls/382","_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments/32579074"},"html":{"href":"https://github.com/libuv/libuv/pull/382#discussion_r32579074"},"pull_request":{"href":"https://api.github.com/repos/libuv/libuv/pulls/382"}}},"pull_request":{"url":"https://api.github.com/repos/libuv/libuv/pulls/382","id":36724196,"html_url":"https://github.com/libuv/libuv/pull/382","diff_url":"https://github.com/libuv/libuv/pull/382.diff","patch_url":"https://github.com/libuv/libuv/pull/382.patch","issue_url":"https://api.github.com/repos/libuv/libuv/issues/382","number":382,"state":"open","locked":false,"title":"Elastic threadpool RFC","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"body":"Something I worked on over the weekend and would like to get some feedback on.  The premise is that threads are started on demand and scale up to some TBD limit.  I'll comment inline on places that still need improvement.\r\n\r\nOne benefit is that it makes it possible to use libuv in an environment that restricts threading.","created_at":"2015-06-02T12:46:22Z","updated_at":"2015-06-16T22:33:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1719a9ebd08b25e1ce57aa37aa74dd83ebb1466","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/libuv/libuv/pulls/382/commits","review_comments_url":"https://api.github.com/repos/libuv/libuv/pulls/382/comments","review_comment_url":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/382/comments","statuses_url":"https://api.github.com/repos/libuv/libuv/statuses/41bddbd2bac72ce1d511ae0d22f26d98c143440d","head":{"label":"bnoordhuis:auto-threadpool","ref":"auto-threadpool","sha":"41bddbd2bac72ce1d511ae0d22f26d98c143440d","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"repo":{"id":29756917,"name":"libuv","full_name":"bnoordhuis/libuv","owner":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bnoordhuis/libuv","description":"Cross-platform asychronous I/O","fork":true,"url":"https://api.github.com/repos/bnoordhuis/libuv","forks_url":"https://api.github.com/repos/bnoordhuis/libuv/forks","keys_url":"https://api.github.com/repos/bnoordhuis/libuv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bnoordhuis/libuv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bnoordhuis/libuv/teams","hooks_url":"https://api.github.com/repos/bnoordhuis/libuv/hooks","issue_events_url":"https://api.github.com/repos/bnoordhuis/libuv/issues/events{/number}","events_url":"https://api.github.com/repos/bnoordhuis/libuv/events","assignees_url":"https://api.github.com/repos/bnoordhuis/libuv/assignees{/user}","branches_url":"https://api.github.com/repos/bnoordhuis/libuv/branches{/branch}","tags_url":"https://api.github.com/repos/bnoordhuis/libuv/tags","blobs_url":"https://api.github.com/repos/bnoordhuis/libuv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bnoordhuis/libuv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bnoordhuis/libuv/git/refs{/sha}","trees_url":"https://api.github.com/repos/bnoordhuis/libuv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bnoordhuis/libuv/statuses/{sha}","languages_url":"https://api.github.com/repos/bnoordhuis/libuv/languages","stargazers_url":"https://api.github.com/repos/bnoordhuis/libuv/stargazers","contributors_url":"https://api.github.com/repos/bnoordhuis/libuv/contributors","subscribers_url":"https://api.github.com/repos/bnoordhuis/libuv/subscribers","subscription_url":"https://api.github.com/repos/bnoordhuis/libuv/subscription","commits_url":"https://api.github.com/repos/bnoordhuis/libuv/commits{/sha}","git_commits_url":"https://api.github.com/repos/bnoordhuis/libuv/git/commits{/sha}","comments_url":"https://api.github.com/repos/bnoordhuis/libuv/comments{/number}","issue_comment_url":"https://api.github.com/repos/bnoordhuis/libuv/issues/comments{/number}","contents_url":"https://api.github.com/repos/bnoordhuis/libuv/contents/{+path}","compare_url":"https://api.github.com/repos/bnoordhuis/libuv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bnoordhuis/libuv/merges","archive_url":"https://api.github.com/repos/bnoordhuis/libuv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bnoordhuis/libuv/downloads","issues_url":"https://api.github.com/repos/bnoordhuis/libuv/issues{/number}","pulls_url":"https://api.github.com/repos/bnoordhuis/libuv/pulls{/number}","milestones_url":"https://api.github.com/repos/bnoordhuis/libuv/milestones{/number}","notifications_url":"https://api.github.com/repos/bnoordhuis/libuv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bnoordhuis/libuv/labels{/name}","releases_url":"https://api.github.com/repos/bnoordhuis/libuv/releases{/id}","created_at":"2015-01-23T22:47:25Z","updated_at":"2015-01-23T22:47:51Z","pushed_at":"2015-06-02T12:47:39Z","git_url":"git://github.com/bnoordhuis/libuv.git","ssh_url":"git@github.com:bnoordhuis/libuv.git","clone_url":"https://github.com/bnoordhuis/libuv.git","svn_url":"https://github.com/bnoordhuis/libuv","homepage":"http://libuv.org/","size":12389,"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":"bddd6a8489e4c8cf47841de6f05becd99fc06f3e","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-06-16T20:53:37Z","pushed_at":"2015-06-16T21:00:23Z","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":18995,"stargazers_count":1715,"watchers_count":1715,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":229,"mirror_url":null,"open_issues_count":71,"forks":229,"open_issues":71,"watchers":1715,"default_branch":"v1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/382"},"html":{"href":"https://github.com/libuv/libuv/pull/382"},"issue":{"href":"https://api.github.com/repos/libuv/libuv/issues/382"},"comments":{"href":"https://api.github.com/repos/libuv/libuv/issues/382/comments"},"review_comments":{"href":"https://api.github.com/repos/libuv/libuv/pulls/382/comments"},"review_comment":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libuv/libuv/pulls/382/commits"},"statuses":{"href":"https://api.github.com/repos/libuv/libuv/statuses/41bddbd2bac72ce1d511ae0d22f26d98c143440d"}}}}