[Ns-developers] timers API -- yans

Tom Henderson tomh at tomh.org
Sun Jan 29 22:27:24 PST 2006


Mathieu Lacage wrote:
> erm. file attached.

>>
>>
>>The major advantage of this solution is that it looks very similar to
>>solution 1) which means that users should be able to switch from
>>one to the other.

Can't you make them exactly the same API:
- replace:
 >>    Simulator::remove (m_event_to_cancel);
 >>    m_event_to_cancel->destroy ();
 >>    m_event_to_cancel = 0;
with
 >>    m_event_to_cancel->cancel();
 >>    m_event_to_cancel = 0;
in both cases?

In first case, cancel will do a Simulator::remove and then destroy the 
event immediately.  In second case, cancel sets a flag in the event, and 
the scheduler destroys the event when it encounters it later (or puts it 
on a free list); scheduler still holds a reference to the cancelled event.

-
>>
>>While the API presented above is simple and does the job, it requires 
>>quite a bit of not-so-nice/ugly-looking code to deal properly with 
>>resource management. The crux of the problem is that the user is 
>>requested to maintain correctly the state of the m_event_to_cancel
>>variable by assigning 0 to it when the variable goes out of scope.

Can you give an example where you think the above is a problem?

Tom



More information about the Ns-developers mailing list