From 93d5a2e19503ebb3559d1ec2d5f5d3297c59e8b8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Jan 2014 10:30:30 +0800 Subject: [PATCH] Fix invoking non-exist method when quiting. --- common/node_bindings.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/node_bindings.cc b/common/node_bindings.cc index a349aef011f9..317f679599dc 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -220,11 +220,20 @@ void NodeBindings::WakeupEmbedThread() { void NodeBindings::EmbedThreadRunner(void *arg) { NodeBindings* self = static_cast(arg); - while (!self->embed_closed_) { + while (true) { // Wait for the main loop to deal with events. uv_sem_wait(&self->embed_sem_); + if (self->embed_closed_) + break; + // Wait for something to happen in uv loop. + // Note that the PollEvents() is implemented by derived classes, so when + // this class is being destructed the PollEvents() would not be available + // anymore. Because of it we must make sure we only invoke PollEvents() + // when this class is alive. self->PollEvents(); + if (self->embed_closed_) + break; // Deal with event in main thread. self->WakeupMainThread();