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

Unified Diff: runtime/vm/message_handler.cc

Issue 1312793004: Fix NotifyPauseOnStart and NotifyPauseOnExit dead lock (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/message_handler.cc
diff --git a/runtime/vm/message_handler.cc b/runtime/vm/message_handler.cc
index 6a473dd74033f4c6d019be2437de0c7a8ec29aa9..d330c0f64a68d462b6ccc39ae5c1bcf20c653d9a 100644
--- a/runtime/vm/message_handler.cc
+++ b/runtime/vm/message_handler.cc
@@ -235,6 +235,7 @@ void MessageHandler::TaskCallback() {
ASSERT(Isolate::Current() == NULL);
bool ok = true;
bool run_end_callback = false;
+ bool notify_paused_on_exit = false;
{
MonitorLocker ml(&monitor_);
// Initialize the message handler by running its start function,
@@ -242,7 +243,12 @@ void MessageHandler::TaskCallback() {
// main() function.
if (pause_on_start()) {
if (!paused_on_start_) {
+ // Temporarily drop the lock when calling out to NotifyPauseOnStart.
+ // This avoids a dead lock that can occur when this message handler
+ // tries to post a message while a message is being posted to it.
+ monitor_.Exit();
NotifyPauseOnStart();
+ monitor_.Enter();
paused_on_start_ = true;
}
HandleMessages(false, false);
@@ -278,7 +284,7 @@ void MessageHandler::TaskCallback() {
OS::PrintErr("Isolate %s paused before exiting. "
"Use the Observatory to release it.\n", name());
}
- NotifyPauseOnExit();
+ notify_paused_on_exit = true;
paused_on_exit_ = true;
}
} else {
@@ -294,6 +300,10 @@ void MessageHandler::TaskCallback() {
}
}
}
+ // At this point we no longer hold the message handler lock.
+ if (notify_paused_on_exit) {
+ NotifyPauseOnExit();
+ }
if (run_end_callback && end_callback_ != NULL) {
end_callback_(callback_data_);
// The handler may have been deleted after this point.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698