diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 19:27:13 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 19:27:13 +0000 |
commit | f1cbc4644f1c41954e5f3562d723a471139ff465 (patch) | |
tree | 937b744ca37c95105eb81663f9049e8ca3c27e9f /base/thread_unittest.cc | |
parent | 89ca511940175e66299235af11ae5c1cd24bc7f4 (diff) | |
download | chromium_src-f1cbc4644f1c41954e5f3562d723a471139ff465.zip chromium_src-f1cbc4644f1c41954e5f3562d723a471139ff465.tar.gz chromium_src-f1cbc4644f1c41954e5f3562d723a471139ff465.tar.bz2 |
Moved Init() startup_data_->event.Signal() because derived classes may
not be safe to use until Init() has been called. As an example,
RenderThread() creates it's IPC::SyncChannel in Init(), so it isn't
safe to call Send() method until after.
Change tested explicitly on Mac Win Linux.
Review URL: http://codereview.chromium.org/18508
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread_unittest.cc')
-rw-r--r-- | base/thread_unittest.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/base/thread_unittest.cc b/base/thread_unittest.cc index 085df71..083456d 100644 --- a/base/thread_unittest.cc +++ b/base/thread_unittest.cc @@ -37,6 +37,20 @@ class SleepSome : public Task { int msec_; }; +class SleepInsideInitThread : public Thread { + public: + SleepInsideInitThread() : Thread("none") { init_called_ = false; } + virtual ~SleepInsideInitThread() { } + + virtual void Init() { + PlatformThread::Sleep(1000); + init_called_ = true; + } + bool InitCalled() { return init_called_; } + private: + bool init_called_; +}; + } // namespace TEST_F(ThreadTest, Restart) { @@ -107,3 +121,12 @@ TEST_F(ThreadTest, ThreadName) { EXPECT_TRUE(a.Start()); EXPECT_EQ("ThreadName", a.thread_name()); } + +// Make sure we can't use a thread between Start() and Init(). +TEST_F(ThreadTest, SleepInsideInit) { + SleepInsideInitThread t; + EXPECT_FALSE(t.InitCalled()); + t.Start(); + EXPECT_TRUE(t.InitCalled()); +} + |