[vm, test] Fix race in shutdown of MessageHandler_Run.

Bug: https://github.com/dart-lang/sdk/issues/39611
Change-Id: I9bd55304646dbc2d1b6fad41b3f31c2ff9384b09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138049
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2020-03-03 16:51:51 +00:00
committed by commit-bot@chromium.org
parent 8fa6e9d20e
commit e9cefe7c08
+8
View File
@@ -333,10 +333,12 @@ struct ThreadStartInfo {
MessageHandler* handler;
Dart_Port* ports;
int count;
ThreadJoinId join_id;
};
static void SendMessages(uword param) {
ThreadStartInfo* info = reinterpret_cast<ThreadStartInfo*>(param);
info->join_id = OSThread::GetCurrentThreadJoinId(OSThread::Current());
MessageHandler* handler = info->handler;
MessageHandlerTestPeer handler_peer(handler);
for (int i = 0; i < info->count; i++) {
@@ -380,6 +382,7 @@ VM_UNIT_TEST_CASE(MessageHandler_Run) {
info.handler = &handler;
info.ports = ports;
info.count = 10;
info.join_id = OSThread::kInvalidThreadJoinId;
OSThread::Start("SendMessages", SendMessages, reinterpret_cast<uword>(&info));
// Wait for the messages to be handled.
@@ -399,6 +402,11 @@ VM_UNIT_TEST_CASE(MessageHandler_Run) {
handler_peer.decrement_live_ports();
EXPECT(!handler.HasLivePorts());
}
// Must join the thread or the VM shutdown is racing with any VM state the
// thread touched.
ASSERT(info.join_id != OSThread::kInvalidThreadJoinId);
OSThread::Join(info.join_id);
}
} // namespace dart