Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Issue 1131513007: Reland (3rd try): Lazily initialize MessageLoop for faster thread startup (Closed)

Created:
5 years, 7 months ago by kinuko
Modified:
5 years, 7 months ago
Reviewers:
Nico, jam
CC:
chromium-reviews, tim+watch_chromium.org, cbentzel+watch_chromium.org, sadrul, zea+watch_chromium.org, maxbogue+watch_chromium.org, jam, pvalenzuela+watch_chromium.org, plaree+watch_chromium.org, asvitkine+watch_chromium.org, darin-cc_chromium.org, erikwright+watch_chromium.org, maniscalco+watch_chromium.org, Takashi Toyoshima
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Reland (3rd try): Lazily initialize MessageLoop for faster thread startup Original review: https://codereview.chromium.org/1011683002/ 2nd try: https://codereview.chromium.org/1129953004/ 2nd try reverted due to race reports on Linux: https://crbug.com/489263 Data races on valid_thread_id_ after r330329 This fixes: - Race in MessageLoopProxyImpl by introducing lock - Race in BrowserMainLoop/BrowserThreadImpl, where BrowserThread::CurrentlyOn() called on one of BrowserThreads tries to touch other thread's message_loop() via global thread table. Reg: the latter race, the code flow that causes this race is like following: // On the main thread, we create all known browser threads: for (...) { { AutoLock lock(g_lock); g_threads[id] = new BrowserProcessSubThread(); } // [A] This initializes the thread's message_loop, which causes a race // against [B] in the new code because new threads can start running // immediately. thread->StartWithOptions(); } // On the new thread's main function, it calls CurrentlyOn() which does: { // [B] This touches other thread's Thread::message_loop. AutoLock lock(g_lock); return g_threads[other_thread_id] && g_threads[other_thread_id]->message_loop() == MessageLoop::current(); } This was safe before because both message_loop initialization and the first call to CurrentlyOn() on the new thread was done synchronously in StartWithOptions() while the main thread was blocked. In the new code new threads can start accessing message_loop() asynchronously while the main thread's for loop is running. PS1 is the original patch (2nd try) that got reverted. BUG=465458, 489263 Committed: https://crrev.com/7f68f8735355c1c73557c3cfb294b441901fc31d Cr-Commit-Position: refs/heads/master@{#331235}

Patch Set 1 #

Patch Set 2 : fix race in MessageLoopProxyImpl #

Patch Set 3 : fix race in BrowserThreadImpl #

Total comments: 1

Patch Set 4 : remove unnecessary include #

Unified diffs Side-by-side diffs Delta from patch set Stats (+300 lines, -181 lines) Patch
M base/message_loop/incoming_task_queue.h View 3 chunks +10 lines, -0 lines 0 comments Download
M base/message_loop/incoming_task_queue.cc View 3 chunks +26 lines, -10 lines 0 comments Download
M base/message_loop/message_loop.h View 5 chunks +36 lines, -7 lines 0 comments Download
M base/message_loop/message_loop.cc View 4 chunks +47 lines, -33 lines 0 comments Download
M base/message_loop/message_loop_proxy_impl.h View 1 3 chunks +7 lines, -1 line 0 comments Download
M base/message_loop/message_loop_proxy_impl.cc View 1 2 chunks +8 lines, -1 line 0 comments Download
M base/message_loop/message_pump_perftest.cc View 3 chunks +0 lines, -5 lines 0 comments Download
M base/threading/platform_thread.h View 1 chunk +4 lines, -0 lines 0 comments Download
M base/threading/platform_thread_win.cc View 1 chunk +3 lines, -2 lines 0 comments Download
M base/threading/thread.h View 6 chunks +25 lines, -12 lines 0 comments Download
M base/threading/thread.cc View 7 chunks +93 lines, -81 lines 0 comments Download
M base/threading/thread_id_name_manager_unittest.cc View 3 chunks +6 lines, -6 lines 0 comments Download
M base/threading/thread_unittest.cc View 1 chunk +3 lines, -2 lines 0 comments Download
M chrome/browser/io_thread.h View 1 2 3 1 chunk +0 lines, -1 line 0 comments Download
M chrome/browser/io_thread.cc View 1 2 3 1 chunk +0 lines, -5 lines 0 comments Download
M chrome/browser/metrics/thread_watcher_android_unittest.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/metrics/thread_watcher_unittest.cc View 1 2 3 2 chunks +4 lines, -4 lines 0 comments Download
M chrome/browser/sync/glue/sync_backend_registrar_unittest.cc View 1 chunk +3 lines, -0 lines 0 comments Download
M content/browser/browser_thread_impl.h View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M content/browser/browser_thread_impl.cc View 1 2 2 chunks +10 lines, -7 lines 0 comments Download
M content/public/browser/browser_thread_delegate.h View 1 chunk +0 lines, -3 lines 0 comments Download
M content/public/test/test_browser_thread.h View 1 chunk +4 lines, -0 lines 0 comments Download
M content/public/test/test_browser_thread.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M net/android/network_change_notifier_android.cc View 1 chunk +3 lines, -0 lines 0 comments Download
M net/test/embedded_test_server/embedded_test_server.cc View 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 24 (15 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1131513007/40001
5 years, 7 months ago (2015-05-20 12:36:44 UTC) #5
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: android_chromium_gn_compile_dbg on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/android_chromium_gn_compile_dbg/builds/73292)
5 years, 7 months ago (2015-05-20 12:45:09 UTC) #7
kinuko
3rd attempt, thanks for reviewing this multiple times. Nico: could you review changes from PS1? ...
5 years, 7 months ago (2015-05-22 11:58:41 UTC) #16
jam
lgtm
5 years, 7 months ago (2015-05-22 15:26:30 UTC) #17
Nico
lgmt
5 years, 7 months ago (2015-05-22 18:05:03 UTC) #18
Nico
lgtm too
5 years, 7 months ago (2015-05-22 18:05:10 UTC) #19
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1131513007/180001
5 years, 7 months ago (2015-05-23 09:40:55 UTC) #22
commit-bot: I haz the power
Committed patchset #4 (id:180001)
5 years, 7 months ago (2015-05-23 11:38:49 UTC) #23
commit-bot: I haz the power
5 years, 7 months ago (2015-05-23 11:39:42 UTC) #24
Message was sent while issue was closed.
Patchset 4 (id:??) landed as
https://crrev.com/7f68f8735355c1c73557c3cfb294b441901fc31d
Cr-Commit-Position: refs/heads/master@{#331235}

Powered by Google App Engine
This is Rietveld 408576698