An example of scheduling events in a background thread. More...
#include "ns3/simulator.h"
#include "ns3/realtime-simulator-impl.h"
#include "ns3/nstime.h"
#include "ns3/log.h"
#include "ns3/system-thread.h"
#include "ns3/string.h"
#include "ns3/config.h"
#include "ns3/global-value.h"
#include "ns3/ptr.h"
#include <unistd.h>
#include <sys/time.h>
Go to the source code of this file.
Classes | |
class | FakeNetDevice |
Example class with a method for the background task. More... | |
Functions | |
void | background_function (void) |
An event method called many times from the main thread. More... | |
void | first_function (void) |
An event method called once from the main thread. More... | |
void | inserted_function (void) |
An event method called many times from the background thread. More... | |
void | test (void) |
Example use of ns3::SystemThread. More... | |
Variables | |
bool | gFirstRun = false |
Check that the event functions run in the intended order. More... | |
An example of scheduling events in a background thread.
See ns3::SystemThread, ns3::SimulatorImpl::ScheduleWithContext
Definition in file main-test-sync.cc.
void background_function | ( | void | ) |
An event method called many times from the main thread.
Definition at line 59 of file main-test-sync.cc.
References gFirstRun, ns3::Simulator::Now(), NS_ASSERT, and NS_LOG_UNCOND.
Referenced by test().
void first_function | ( | void | ) |
An event method called once from the main thread.
Definition at line 68 of file main-test-sync.cc.
References gFirstRun, ns3::Simulator::Now(), and NS_LOG_UNCOND.
Referenced by test().
void inserted_function | ( | void | ) |
An event method called many times from the background thread.
Definition at line 50 of file main-test-sync.cc.
References gFirstRun, ns3::Simulator::Now(), NS_ASSERT, and NS_LOG_UNCOND.
Referenced by FakeNetDevice::Doit3().
void test | ( | void | ) |
Example use of ns3::SystemThread.
This example is a complete simulation. It schedules first_function
and many executions of background_function
to execute in the main (foreground) thread. It also launches a background thread with an instance of FakeNetDevice, which schedules many instances of inserted_function
.
Definition at line 115 of file main-test-sync.cc.
References background_function(), ns3::GlobalValue::Bind(), ns3::Simulator::Destroy(), FakeNetDevice::Doit3(), first_function(), ns3::SystemThread::Join(), ns3::MakeCallback(), ns3::MakeEvent(), ns3::Simulator::Run(), ns3::Simulator::Schedule(), ns3::Simulator::ScheduleWithContext(), ns3::Seconds(), ns3::SystemThread::Start(), and ns3::Simulator::Stop().
Referenced by ns3::TestRunnerImpl::FilterTests(), ns3::ZetaRandomVariable::GetValue(), ChannelCoordinationTestCase::NotifyCchStartNow(), ChannelCoordinationTestCase::NotifyGuardStartNow(), ChannelCoordinationTestCase::NotifySchStartNow(), ns3::Ptr< T >::operator Tester *(), ns3::TestRunnerImpl::PrintTestNameList(), ns3::TestRunnerImpl::Run(), ns3::TestCase::Run(), ns3::DummyCongControl::SetCallback(), ns3::Ipv4L3Protocol::SourceAddressSelection(), and ns3::Ipv6L3Protocol::SourceAddressSelection().
bool gFirstRun = false |
Check that the event functions run in the intended order.
Definition at line 46 of file main-test-sync.cc.
Referenced by background_function(), first_function(), and inserted_function().