Index: base/threading/thread.cc |
diff --git a/base/threading/thread.cc b/base/threading/thread.cc |
index 98610a63c09875878ffceca6417d7af16980ca89..df8f661bc19e50f7d71a3c8fdc0e54351f1f3260 100644 |
--- a/base/threading/thread.cc |
+++ b/base/threading/thread.cc |
@@ -28,7 +28,7 @@ namespace { |
// because its Stop method was called. This allows us to catch cases where |
// MessageLoop::QuitWhenIdle() is called directly, which is unexpected when |
// using a Thread to setup and run a MessageLoop. |
-base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool = |
+base::LazyInstance<base::ThreadLocalBoolean>::Leaky lazy_tls_bool = |
LAZY_INSTANCE_INITIALIZER; |
} // namespace |
@@ -74,6 +74,8 @@ bool Thread::StartWithOptions(const Options& options) { |
DCHECK(owning_sequence_checker_.CalledOnValidSequencedThread()); |
DCHECK(!message_loop_); |
DCHECK(!IsRunning()); |
+ DCHECK(!stopping_) << "Starting a non-joinable thread a second time? That's " |
+ << "not allowed!"; |
#if defined(OS_WIN) |
DCHECK((com_status_ != STA) || |
(options.message_loop_type == MessageLoop::TYPE_UI)); |
@@ -100,8 +102,13 @@ bool Thread::StartWithOptions(const Options& options) { |
// fixed). |
{ |
AutoLock lock(thread_lock_); |
- if (!PlatformThread::CreateWithPriority(options.stack_size, this, &thread_, |
- options.priority)) { |
+ bool success = |
+ options.joinable |
+ ? PlatformThread::CreateWithPriority(options.stack_size, this, |
+ &thread_, options.priority) |
+ : PlatformThread::CreateNonJoinableWithPriority( |
+ options.stack_size, this, options.priority); |
+ if (!success) { |
DLOG(ERROR) << "failed to create thread"; |
message_loop_ = nullptr; |
return false; |
@@ -141,11 +148,12 @@ void Thread::Stop() { |
// DCHECK(owning_sequence_checker_.CalledOnValidSequencedThread()); |
AutoLock lock(thread_lock_); |
danakj
2016/07/22 21:00:39
does this need to be above StopSoon?
gab
2016/07/25 16:07:40
Well... hopefully it's fully gone soon but in the
|
+ StopSoon(); |
+ |
+ // Can't join if the |thread_| is either already gone or is non-joinable. |
if (thread_.is_null()) |
return; |
- StopSoon(); |
- |
// Wait for the thread to exit. |
// |
// TODO(darin): Unfortunately, we need to keep |message_loop_| around until |