【发布时间】:2016-02-22 00:21:17
【问题描述】:
我正在使用 NS3 框架来运行具有各种配置的 Wi-Fi 模拟。我想使用 std::thread 在一个进程中同时运行许多(数百个)模拟。
这是我的代码,部分配置已编辑:
void simulation(RateAdaptation rate_adaptation,
const bool channel_fading,
// In meters, between AP and station.
const uint32_t distance)
{
ns3::SeedManager::SetSeed(++seed);
ns3::NodeContainer station_node, ap_node;
station_node.Create(1);
ap_node.Create(1);
ns3::YansWifiChannelHelper channel;
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
channel.AddPropagationLoss( "ns3::LogDistancePropagationLossModel");
// About 130 lines of more configuration for the simulation and
// function parameters.
ns3::Simulator::Stop(ns3::Seconds(10.0));
ns3::Ptr<ns3::FlowMonitor> flowmon;
ns3::FlowMonitorHelper *flowmonHelper = new ns3::FlowMonitorHelper();
flowmon = flowmonHelper->InstallAll();
ns3::Simulator::Run();
ns3::Simulator::Destroy();
flow_output(flowmon, flowmonHelper);
}
int main(int argc, char *argv[])
{
std::vector<std::thread> jobs;
for (uint32_t i = 0; i < 20; ++i)
{
uint32_t varying_distance = 5*(i+1);
jobs.push_back(std::thread(simulation,
RateAdaptation::Aarf,
false,
varying_distance));
}
for (auto it = jobs.begin(); it < jobs.end(); ++it)
{
it.join();
}
return 0;
}
当我只为作业中的一项作业运行此代码时,它运行良好,但对于任何更大的数字(比如两个),我会得到如下输出:
assert failed. cond="SystemThread::Equals (m_main)", msg="Simulator::ScheduleDestroy Thread-unsafe invocation!", file=../src/core/model/default-simulator-impl.cc, line=289
terminate called without an active exception
Command ['[redacted]'] terminated with signal SIGIOT. Run it under a debugger to get more information (./waf --run <program> --comm and-template="gdb --args %s <args>").
确实在 Valgrind 中运行它会返回数百个问题。
两个问题:
- 是否有可能我做错了什么,NS3 应该支持这一点?
- 已知 NS3 不能并行运行多个模拟吗?
【问题讨论】:
标签: c++ multithreading stdthread ns-3