passing TaskPtr to executor in scheduler to ensure when the
callback is envoked, the Task object is still there
diff --git a/scheduler/task.cc b/scheduler/task.cc
index 4702906..2f72f06 100644
--- a/scheduler/task.cc
+++ b/scheduler/task.cc
@@ -72,5 +72,12 @@
void
Task::execute()
{
- m_scheduler->execute(boost::bind(&Task::run, this));
+ // m_scheduler->execute(boost::bind(&Task::run, this));
+
+ // using a shared_ptr of this to ensure that when invoked from executor
+ // the task object still exists
+ // otherwise, it could be the case that the run() is to be executed, but before it
+ // could finish, the TaskPtr gets deleted from scheduler and the task object
+ // gets destroyed, causing crash
+ m_scheduler->execute(boost::bind(&Task::run, shared_from_this()));
}