diff -r 5949904cf955 examples/realtime/realtime-udp-echo.cc --- a/examples/realtime/realtime-udp-echo.cc Fri Jul 08 06:04:37 2011 -0400 +++ b/examples/realtime/realtime-udp-echo.cc Mon Jul 11 14:18:52 2011 +0200 @@ -113,6 +113,7 @@ // // Now, do the actual simulation. // + Simulator::Stop (Seconds (11.0)); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); diff -r 5949904cf955 src/core/model/realtime-simulator-impl.cc --- a/src/core/model/realtime-simulator-impl.cc Fri Jul 08 06:04:37 2011 -0400 +++ b/src/core/model/realtime-simulator-impl.cc Mon Jul 11 14:18:52 2011 +0200 @@ -428,27 +428,34 @@ m_running = true; m_synchronizer->SetOrigin (m_currentTs); - for (;;) + // Sleep until signalled + uint64_t tsNow; + uint64_t tsDelay = 1000000000; // wait time of 1 second (in nanoseconds) + + while (!m_stop) { - bool done = false; - + bool process = false; { CriticalSection cs (m_mutex); - // - // In all cases we stop when the event list is empty. If you are doing a - // realtime simulation and you want it to extend out for some time, you must - // call StopAt. In the realtime case, this will stick a placeholder event out - // at the end of time. - // - if (m_stop || m_events->IsEmpty ()) + + if (!m_events->IsEmpty ()) { - done = true; + process = true; + } + else + { + // Get current timestamp while holding the critical section + tsNow = m_synchronizer->GetCurrentRealtime (); } } + + if (!process) + { + // Sleep until signalled + tsNow = m_synchronizer->Synchronize (tsNow, tsDelay); - if (done) - { - break; + // Re-check event queue + continue; } ProcessOneEvent ();