{"action":"created","comment":{"url":"https://api.github.com/repos/citra-emu/citra/pulls/comments/92924415","pull_request_review_id":13448937,"id":92924415,"diff_hunk":"@@ -120,6 +120,9 @@ void Thread::Stop() {\n     u32 tls_slot =\n         ((tls_address - Memory::TLS_AREA_VADDR) % Memory::PAGE_SIZE) / Memory::TLS_ENTRY_SIZE;\n     Kernel::g_current_process->tls_slots[tls_page].reset(tls_slot);\n+\n+    // Remove the thread from the thread list\n+    thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), this), thread_list.end());","path":"src/core/hle/kernel/thread.cpp","position":24,"original_position":24,"commit_id":"662fba0e62225c6107ee9d8f579b0e8cb515f664","original_commit_id":"662fba0e62225c6107ee9d8f579b0e8cb515f664","user":{"login":"TTFH","id":23284861,"avatar_url":"https://avatars.githubusercontent.com/u/23284861?v=3","gravatar_id":"","url":"https://api.github.com/users/TTFH","html_url":"https://github.com/TTFH","followers_url":"https://api.github.com/users/TTFH/followers","following_url":"https://api.github.com/users/TTFH/following{/other_user}","gists_url":"https://api.github.com/users/TTFH/gists{/gist_id}","starred_url":"https://api.github.com/users/TTFH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TTFH/subscriptions","organizations_url":"https://api.github.com/users/TTFH/orgs","repos_url":"https://api.github.com/users/TTFH/repos","events_url":"https://api.github.com/users/TTFH/events{/privacy}","received_events_url":"https://api.github.com/users/TTFH/received_events","type":"User","site_admin":false},"body":"This line makes emulator to crash when click in \"Emulation => Close\" in TLZ A Link Between Worlds.\r\n\r\nSegmentation fault in ReleaseThreadMutexes()","created_at":"2016-12-17T16:27:22Z","updated_at":"2016-12-17T16:27:22Z","html_url":"https://github.com/citra-emu/citra/pull/2345#discussion_r92924415","pull_request_url":"https://api.github.com/repos/citra-emu/citra/pulls/2345","_links":{"self":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/comments/92924415"},"html":{"href":"https://github.com/citra-emu/citra/pull/2345#discussion_r92924415"},"pull_request":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/2345"}}},"pull_request":{"url":"https://api.github.com/repos/citra-emu/citra/pulls/2345","id":98440164,"html_url":"https://github.com/citra-emu/citra/pull/2345","diff_url":"https://github.com/citra-emu/citra/pull/2345.diff","patch_url":"https://github.com/citra-emu/citra/pull/2345.patch","issue_url":"https://api.github.com/repos/citra-emu/citra/issues/2345","number":2345,"state":"open","locked":false,"title":"Thread: remove the thread from the thread list when exiting","user":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"body":"Currently we leave all dead thread in the `thread_list` and never remove them until exiting the game. This has a significant impact on game that loves to create small threads frequently (such as Pokemon Sun, which creates thousands of threads in 10 minutes). In this case, the `thread_list` grows up quickly and slows down all functions that iterating over the list, as users reported \"games slow down after an hour\".\r\n\r\nI did a profiling on Pokemon running for 40 minutes, with the character standing there without any input. The frame rate drops from 25 FPS at the beginning to 20 FPS at the end. The profiling shows a time difference spending on a function between the beginning and the end:\r\n\r\nThe first 5 minutes:\r\n![fast](https://cloud.githubusercontent.com/assets/4592895/21286095/3f098906-c453-11e6-85ec-cb10f35b78f8.PNG)\r\n\r\nThe last 5 minutes:\r\n![slow](https://cloud.githubusercontent.com/assets/4592895/21286097/45559b92-c453-11e6-9f17-1c1f49d6dbb8.PNG)\r\n\r\nThe profiling results after the change shows no difference in the function between the first and the last 5 minutes.\r\n\r\nTo avoid use-after-free, I turn `current_thread` into a `SharedPtr`, ~~as well as the return type of `GetCurrentThread`~~. But I am not confident with these changes. Please help me check if the memory management is ok.","created_at":"2016-12-17T10:22:04Z","updated_at":"2016-12-17T16:27:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ef78a61b2fac488a7d287e8bc4881ca864d4e00","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/citra-emu/citra/pulls/2345/commits","review_comments_url":"https://api.github.com/repos/citra-emu/citra/pulls/2345/comments","review_comment_url":"https://api.github.com/repos/citra-emu/citra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/citra-emu/citra/issues/2345/comments","statuses_url":"https://api.github.com/repos/citra-emu/citra/statuses/662fba0e62225c6107ee9d8f579b0e8cb515f664","head":{"label":"wwylele:no-zombie-thread","ref":"no-zombie-thread","sha":"662fba0e62225c6107ee9d8f579b0e8cb515f664","user":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"repo":{"id":53776373,"name":"citra","full_name":"wwylele/citra","owner":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wwylele/citra","description":"Nintendo 3DS Emulator","fork":true,"url":"https://api.github.com/repos/wwylele/citra","forks_url":"https://api.github.com/repos/wwylele/citra/forks","keys_url":"https://api.github.com/repos/wwylele/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wwylele/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wwylele/citra/teams","hooks_url":"https://api.github.com/repos/wwylele/citra/hooks","issue_events_url":"https://api.github.com/repos/wwylele/citra/issues/events{/number}","events_url":"https://api.github.com/repos/wwylele/citra/events","assignees_url":"https://api.github.com/repos/wwylele/citra/assignees{/user}","branches_url":"https://api.github.com/repos/wwylele/citra/branches{/branch}","tags_url":"https://api.github.com/repos/wwylele/citra/tags","blobs_url":"https://api.github.com/repos/wwylele/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wwylele/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wwylele/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/wwylele/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wwylele/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/wwylele/citra/languages","stargazers_url":"https://api.github.com/repos/wwylele/citra/stargazers","contributors_url":"https://api.github.com/repos/wwylele/citra/contributors","subscribers_url":"https://api.github.com/repos/wwylele/citra/subscribers","subscription_url":"https://api.github.com/repos/wwylele/citra/subscription","commits_url":"https://api.github.com/repos/wwylele/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/wwylele/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/wwylele/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/wwylele/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/wwylele/citra/contents/{+path}","compare_url":"https://api.github.com/repos/wwylele/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wwylele/citra/merges","archive_url":"https://api.github.com/repos/wwylele/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wwylele/citra/downloads","issues_url":"https://api.github.com/repos/wwylele/citra/issues{/number}","pulls_url":"https://api.github.com/repos/wwylele/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/wwylele/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/wwylele/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wwylele/citra/labels{/name}","releases_url":"https://api.github.com/repos/wwylele/citra/releases{/id}","deployments_url":"https://api.github.com/repos/wwylele/citra/deployments","created_at":"2016-03-13T09:09:07Z","updated_at":"2016-11-16T15:38:29Z","pushed_at":"2016-12-17T12:18:53Z","git_url":"git://github.com/wwylele/citra.git","ssh_url":"git@github.com:wwylele/citra.git","clone_url":"https://github.com/wwylele/citra.git","svn_url":"https://github.com/wwylele/citra","homepage":"https://citra-emu.org","size":14507,"stargazers_count":8,"watchers_count":8,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":8,"default_branch":"master"}},"base":{"label":"citra-emu:master","ref":"master","sha":"2ca548bbe52bb72cdd269893571b92ad185107a5","user":{"login":"citra-emu","id":7605670,"avatar_url":"https://avatars.githubusercontent.com/u/7605670?v=3","gravatar_id":"","url":"https://api.github.com/users/citra-emu","html_url":"https://github.com/citra-emu","followers_url":"https://api.github.com/users/citra-emu/followers","following_url":"https://api.github.com/users/citra-emu/following{/other_user}","gists_url":"https://api.github.com/users/citra-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/citra-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citra-emu/subscriptions","organizations_url":"https://api.github.com/users/citra-emu/orgs","repos_url":"https://api.github.com/users/citra-emu/repos","events_url":"https://api.github.com/users/citra-emu/events{/privacy}","received_events_url":"https://api.github.com/users/citra-emu/received_events","type":"Organization","site_admin":false},"repo":{"id":19866730,"name":"citra","full_name":"citra-emu/citra","owner":{"login":"citra-emu","id":7605670,"avatar_url":"https://avatars.githubusercontent.com/u/7605670?v=3","gravatar_id":"","url":"https://api.github.com/users/citra-emu","html_url":"https://github.com/citra-emu","followers_url":"https://api.github.com/users/citra-emu/followers","following_url":"https://api.github.com/users/citra-emu/following{/other_user}","gists_url":"https://api.github.com/users/citra-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/citra-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citra-emu/subscriptions","organizations_url":"https://api.github.com/users/citra-emu/orgs","repos_url":"https://api.github.com/users/citra-emu/repos","events_url":"https://api.github.com/users/citra-emu/events{/privacy}","received_events_url":"https://api.github.com/users/citra-emu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citra-emu/citra","description":"Nintendo 3DS Emulator","fork":false,"url":"https://api.github.com/repos/citra-emu/citra","forks_url":"https://api.github.com/repos/citra-emu/citra/forks","keys_url":"https://api.github.com/repos/citra-emu/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citra-emu/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citra-emu/citra/teams","hooks_url":"https://api.github.com/repos/citra-emu/citra/hooks","issue_events_url":"https://api.github.com/repos/citra-emu/citra/issues/events{/number}","events_url":"https://api.github.com/repos/citra-emu/citra/events","assignees_url":"https://api.github.com/repos/citra-emu/citra/assignees{/user}","branches_url":"https://api.github.com/repos/citra-emu/citra/branches{/branch}","tags_url":"https://api.github.com/repos/citra-emu/citra/tags","blobs_url":"https://api.github.com/repos/citra-emu/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citra-emu/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citra-emu/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/citra-emu/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citra-emu/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/citra-emu/citra/languages","stargazers_url":"https://api.github.com/repos/citra-emu/citra/stargazers","contributors_url":"https://api.github.com/repos/citra-emu/citra/contributors","subscribers_url":"https://api.github.com/repos/citra-emu/citra/subscribers","subscription_url":"https://api.github.com/repos/citra-emu/citra/subscription","commits_url":"https://api.github.com/repos/citra-emu/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/citra-emu/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/citra-emu/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/citra-emu/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/citra-emu/citra/contents/{+path}","compare_url":"https://api.github.com/repos/citra-emu/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citra-emu/citra/merges","archive_url":"https://api.github.com/repos/citra-emu/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citra-emu/citra/downloads","issues_url":"https://api.github.com/repos/citra-emu/citra/issues{/number}","pulls_url":"https://api.github.com/repos/citra-emu/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/citra-emu/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/citra-emu/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citra-emu/citra/labels{/name}","releases_url":"https://api.github.com/repos/citra-emu/citra/releases{/id}","deployments_url":"https://api.github.com/repos/citra-emu/citra/deployments","created_at":"2014-05-16T18:33:15Z","updated_at":"2016-12-17T15:37:44Z","pushed_at":"2016-12-17T16:25:51Z","git_url":"git://github.com/citra-emu/citra.git","ssh_url":"git@github.com:citra-emu/citra.git","clone_url":"https://github.com/citra-emu/citra.git","svn_url":"https://github.com/citra-emu/citra","homepage":"https://citra-emu.org","size":14739,"stargazers_count":2587,"watchers_count":2587,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":671,"mirror_url":null,"open_issues_count":212,"forks":671,"open_issues":212,"watchers":2587,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/2345"},"html":{"href":"https://github.com/citra-emu/citra/pull/2345"},"issue":{"href":"https://api.github.com/repos/citra-emu/citra/issues/2345"},"comments":{"href":"https://api.github.com/repos/citra-emu/citra/issues/2345/comments"},"review_comments":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/2345/comments"},"review_comment":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/2345/commits"},"statuses":{"href":"https://api.github.com/repos/citra-emu/citra/statuses/662fba0e62225c6107ee9d8f579b0e8cb515f664"}}}}
{"actor":{"display_login":"TTFH"}}