An obvious problem with the Ethernet simulation was the enormous variance on the transmission-delay measurements. Antithetic variates are a variance-reduction technique based on mitigating autocorrelation in a stream of uniform random samples by creating mirror images of the autocorrelations. The hope is that running the simulation with a uniform random variate X and its antithetic variate 1 - X will cause the mirrored autocorrelations to cancel, resulting in less correlation and a smaller variance.
1) if not event_q.empty() event e = event_q.top() event_q.pop() e->trigger() current_time = e->trigger_time()
|
2) if not event_q.empty() event e = event_q.top() event_q.pop() current_time = e->trigger_time() e->trigger()
|
are before-debugging and after-debugging snapshots of the working part of the event scheduler in the C++ framework used to implement the Ethernet simulation. Which is which; that is, which is the before-debugging snapshot and which is the after-debugging snapshot? Explain
Hint 1: the error has nothing to do with C++; I made the same mistake in the Smalltalk code.
Hint 2: this incorrect code
if not event_q.empty() event & e = event_q.top() // blah blah blah event_q.pop()
is a C++-specific example (that is, it can't occur in the Smalltalk code) of the same error as was made above.
Extra Credit (+5 point maximum, 100 total points maximum): Explain the error in Hint 2.
The only difference between the two code snapshots are the order in which events are triggered and the clock is updated; apparently, the problem has to do with time and event triggering. In snapshot 1, the event is triggered and then the clock is updated to the time at which the event was triggered. If the triggered event were to read the clock, it would find the time to be less than time at which the event should have been triggered. In snapshot 2, the clock is updated to the time at which the event should occur and then the event is triggered. In this case the triggered event observes the correct clock time.
Extra credit: The declaration is supposed to remember the queue head so the queue head can be popped before the associated event is triggered (why is this necessary?). Unfortunately, the declaration creates a reference to (that is, an alias) rather than a copy of the queue head, which leads to undefined behavior after the queue is popped.
This page last modified on 21 April 2005. |