Re: What kind of pattern is this?
On 10.11.2011 11:55, Goran wrote:
"delete this" is seen in places, and, beside intrusive refcounting, I
am yet to see a reason why it is a good idea. In your case, ownership
of the object is effectively taken by whoever is going to call
OnCompleted. So that somebody can do
p->OnCompleted();
delete p;
No, OnCompleted is private. So the class owns itself.
Basically the class requests several information from different places
asynchronously and registers completion call-backs. Once sufficient
information is available (not necessarily all) the remaining
subscriptions are canceled and the original task, that has been
suspended because of missing dependencies, is rescheduled to a thread
pool. This lets me deal with complex dependency trees with no need to
keep track of all suspended tasks and their dependencies at a central
location, with all its concurrency issues. The required information to
control all the thousands of dependencies is simply held in the
structure of the OnChange event subscriptions.
or better yet
auto_ptr<ReshceduleWorker>(p)->OnCompleted();
This is not an option unless the auto_ptr is a member of
RescheduleWorker which obviously is equivalent to delete this.
and "delete this" should disappear.
"delete this" is usually a sign of underdesigned heap object
ownership.
Well, a better solution for the above scenario would be appreciated.
Marcel