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

Side by Side Diff: runtime/vm/thread_pool.cc

Issue 1555643002: Thread fixes for shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/os_thread.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/thread_pool.h" 5 #include "vm/thread_pool.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 MonitorLocker eml(&exit_monitor_); 100 MonitorLocker eml(&exit_monitor_);
101 101
102 // First tell all the workers to shut down. 102 // First tell all the workers to shut down.
103 Worker* current = saved; 103 Worker* current = saved;
104 OSThread* os_thread = OSThread::Current(); 104 OSThread* os_thread = OSThread::Current();
105 ASSERT(os_thread != NULL); 105 ASSERT(os_thread != NULL);
106 ThreadId id = os_thread->id(); 106 ThreadId id = os_thread->id();
107 while (current != NULL) { 107 while (current != NULL) {
108 Worker* next = current->all_next_; 108 Worker* next = current->all_next_;
109 ThreadId currentId = current->id(); 109 ThreadId currentId = current->id();
110 if (currentId != id) { 110 if (currentId == OSThread::kInvalidThreadId) {
111 // If the thread id is invalid, it means the thread never started
112 // because OSThread creation was disabled. Destroy the Task and Worker.
113 delete current->task_;
114 delete current;
115 current = NULL;
116 } else if (currentId != id) {
111 AddWorkerToShutdownList(current); 117 AddWorkerToShutdownList(current);
112 } 118 }
113 current->Shutdown(); 119 if (current != NULL) {
120 current->Shutdown();
siva 2015/12/30 20:51:02 Why is it necessary to call current->Shutdown() wh
zra 2015/12/30 22:36:28 Thinking about this more, it is not safe for a thr
121 }
114 current = next; 122 current = next;
115 } 123 }
116 saved = NULL; 124 saved = NULL;
117 125
118 // Wait until all workers will exit. 126 // Wait until all workers will exit.
119 while (shutting_down_workers_ != NULL) { 127 while (shutting_down_workers_ != NULL) {
120 // Here, we are waiting for workers to exit. When a worker exits we will 128 // Here, we are waiting for workers to exit. When a worker exits we will
121 // be notified. 129 // be notified.
122 eml.Wait(); 130 eml.Wait();
123 } 131 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 OSThread* os_thread = OSThread::Current(); 258 OSThread* os_thread = OSThread::Current();
251 ASSERT(os_thread != NULL); 259 ASSERT(os_thread != NULL);
252 JoinList::AddLocked(os_thread->join_id(), &join_list_); 260 JoinList::AddLocked(os_thread->join_id(), &join_list_);
253 count_stopped_++; 261 count_stopped_++;
254 count_idle_--; 262 count_idle_--;
255 return true; 263 return true;
256 } 264 }
257 265
258 266
259 // Only call while holding the exit_monitor_ 267 // Only call while holding the exit_monitor_
260 void ThreadPool::AddWorkerToShutdownList(Worker* worker) { 268 void ThreadPool::AddWorkerToShutdownList(Worker* worker) {
siva 2015/12/30 20:51:02 ASSERT that the exit_monitor lock is held by the c
zra 2015/12/30 22:36:28 Done.
261 worker->shutdown_next_ = shutting_down_workers_; 269 worker->shutdown_next_ = shutting_down_workers_;
262 shutting_down_workers_ = worker; 270 shutting_down_workers_ = worker;
263 } 271 }
264 272
265 273
266 // Only call while holding the exit_monitor_ 274 // Only call while holding the exit_monitor_
267 bool ThreadPool::RemoveWorkerFromShutdownList(Worker* worker) { 275 bool ThreadPool::RemoveWorkerFromShutdownList(Worker* worker) {
268 ASSERT(worker != NULL); 276 ASSERT(worker != NULL);
269 ASSERT(shutting_down_workers_ != NULL); 277 ASSERT(shutting_down_workers_ != NULL);
siva 2015/12/30 20:51:02 ASSERT that the exit_monitor lock is held by the c
zra 2015/12/30 22:36:28 Done.
270 278
271 // Special case head of list. 279 // Special case head of list.
272 if (shutting_down_workers_ == worker) { 280 if (shutting_down_workers_ == worker) {
273 shutting_down_workers_ = worker->shutdown_next_; 281 shutting_down_workers_ = worker->shutdown_next_;
274 worker->shutdown_next_ = NULL; 282 worker->shutdown_next_ = NULL;
275 return true; 283 return true;
276 } 284 }
277 285
278 for (Worker* current = shutting_down_workers_; 286 for (Worker* current = shutting_down_workers_;
279 current->shutdown_next_ != NULL; 287 current->shutdown_next_ != NULL;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // is not due to a ThreadPool Shutdown. Thus, we simply delete the worker. 482 // is not due to a ThreadPool Shutdown. Thus, we simply delete the worker.
475 // The worker's id is added to the thread pool's join list by 483 // The worker's id is added to the thread pool's join list by
476 // ReleaseIdleWorker, so in the case that the thread pool begins shutting 484 // ReleaseIdleWorker, so in the case that the thread pool begins shutting
477 // down immediately after returning from worker->Loop() above, we still 485 // down immediately after returning from worker->Loop() above, we still
478 // wait for the thread to exit by joining on it in Shutdown(). 486 // wait for the thread to exit by joining on it in Shutdown().
479 delete worker; 487 delete worker;
480 } 488 }
481 } 489 }
482 490
483 } // namespace dart 491 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698