diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 03:45:30 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-13 03:45:30 +0000 |
commit | 5f067a0927c0cfc174a9e89c45983d9d17c606aa (patch) | |
tree | c8dc850dc08351458bf5c0139e94f632d345294c /base/thread.cc | |
parent | 27bcd0d84a420174e6ecb6816793f9713686206e (diff) | |
download | chromium_src-5f067a0927c0cfc174a9e89c45983d9d17c606aa.zip chromium_src-5f067a0927c0cfc174a9e89c45983d9d17c606aa.tar.gz chromium_src-5f067a0927c0cfc174a9e89c45983d9d17c606aa.tar.bz2 |
Don't call Thread::CleanUp() before the MessageLoop destruction observers have run.
This is consistent with the comment for Thread::CleanUp(), which says it runs after the message loop has "stopped".
Certain consumers depend on this ordering to avoid accessing variables which are deleted by Thread::CleanUp().
BUG=39723
TEST=ThreadTest.CleanUp
Review URL: http://codereview.chromium.org/1540002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread.cc')
-rw-r--r-- | base/thread.cc | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/base/thread.cc b/base/thread.cc index aeaa0a1..e916f2c 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -35,7 +35,7 @@ struct Thread::StartupData { event(false, false) {} }; -Thread::Thread(const char *name) +Thread::Thread(const char* name) : stopping_(false), startup_data_(NULL), thread_(0), @@ -134,25 +134,30 @@ void Thread::Run(MessageLoop* message_loop) { } void Thread::ThreadMain() { - // The message loop for this thread. - MessageLoop message_loop(startup_data_->options.message_loop_type); - - // Complete the initialization of our Thread object. - thread_id_ = PlatformThread::CurrentId(); - PlatformThread::SetName(name_.c_str()); - ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. - message_loop.set_thread_name(name_); - message_loop_ = &message_loop; - - // Let the thread do extra initialization. - // Let's do this before signaling we are started. - Init(); - - startup_data_->event.Signal(); - // startup_data_ can't be touched anymore since the starting thread is now - // unlocked. + { + // The message loop for this thread. + MessageLoop message_loop(startup_data_->options.message_loop_type); + + // Complete the initialization of our Thread object. + thread_id_ = PlatformThread::CurrentId(); + PlatformThread::SetName(name_.c_str()); + ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. + message_loop.set_thread_name(name_); + message_loop_ = &message_loop; + + // Let the thread do extra initialization. + // Let's do this before signaling we are started. + Init(); + + startup_data_->event.Signal(); + // startup_data_ can't be touched anymore since the starting thread is now + // unlocked. + + Run(message_loop_); + // Destroy |message_loop| upon leaving this scope. + } - Run(message_loop_); + message_loop_ = NULL; // Let the thread do extra cleanup. CleanUp(); @@ -161,7 +166,6 @@ void Thread::ThreadMain() { DCHECK(GetThreadWasQuitProperly()); // We can't receive messages anymore. - message_loop_ = NULL; thread_id_ = 0; } |