Alfredo Braunstein wrote:

> Angus Leeming wrote:
> 
>> I don't see the bug. You return to the start of the list, I move to the
>> next itme in the list. The 'prev' stuff is safe if ugly, as I understand
>> list.
> 
> Sorry, I was away.
> What if for instance, *prev has dissapeared in the time being? (because of
> multiple calls to kill() in the function called by emiting the signal).
> Are you making some assumption on the implementation of list? The list
> could even become void.
> I think that you cannot make any assumption on the state of the list,
> after emiting the signal.
> 
> Regards, Alfredo

Ooohhhh, that's devious. In that case I think we really need a two pass 
algorithm:

        ListType::iterator it  = forkedCalls.begin();
        ListType::iterator end = forkedCalls.end();
        for (; it != end; ++it) {
                bool remove_it = ...;

                if (remove_it) {
                        // Emit signal. 
                        // Do not remove the item from the list yet.
                        (*it)->emitSignal();
                        delete *it;
                        *it = 0;
                }
        }

        // Check whether any of the list contents have been deleted.
        ListType::iterator it  = forkedCalls.begin();
        while (it != end) {
                if (*it) {
                        ++it;
                else
                        it = forkedCalls.erase(it);
        }

Thoughts?

-- 
Angus

Reply via email to