Пример #1
0
void
step(DhtRunner& dht, std::atomic_uint& done, std::shared_ptr<NodeSet> all_nodes, dht::InfoHash cur_h, unsigned cur_depth)
{
    std::cout << "step at " << cur_h << ", depth " << cur_depth << std::endl;
    done++;
    dht.get(cur_h, [all_nodes](const std::vector<std::shared_ptr<Value>>& /*values*/) {
        return true;
    }, [&,all_nodes,cur_h,cur_depth](bool, const std::vector<std::shared_ptr<Node>>& nodes) {
        all_nodes->insert(nodes.begin(), nodes.end());
        NodeSet sbuck {nodes.begin(), nodes.end()};
        if (not sbuck.empty()) {
            unsigned bdepth = sbuck.size()==1 ? 0u : InfoHash::commonBits((*sbuck.begin())->id, (*std::prev(sbuck.end()))->id);
            unsigned target_depth = std::min(159u, bdepth+3u);
            std::cout << cur_h << " : " << nodes.size() << " nodes; target is " << target_depth << " bits deep (cur " << cur_depth << ")" << std::endl;
            for (unsigned b = cur_depth ; b < target_depth; b++) {
                auto new_h = cur_h;
                new_h.setBit(b, 1);
                step(dht, done, all_nodes, new_h, b+1);
            }
        }
        done--;
        std::cout << done.load() << " operations left, " << all_nodes->size() << " nodes found." << std::endl;
        cv.notify_one();
    });
}
Пример #2
0
void
controller()
{
	while( agents_count != agents_destroyed.load( std::memory_order_acquire ) )
		std::this_thread::yield();

	std::cout << "All agents are destroyed. Take SO Environment some time..."
			<< std::endl;

	std::this_thread::sleep_for( std::chrono::seconds( 1 ) );

	auto env = environment.load( std::memory_order_acquire );
	if( !env )
	{
		std::cerr << "environment cannot be nullptr!" << std::endl;
		std::abort();
	}
	else
		std::cout << "Stopping SO Environment..." << std::endl;
	env->stop();
}
 // ------------------------------------------------------------------------
 unsigned getWidth() const                        { return m_width.load(); }
 // ------------------------------------------------------------------------
 unsigned getHeight() const                      { return m_height.load(); }
Пример #5
0
 bool is_empty() const noexcept {
     return th_stoped_counter.load() == workers.size(); //TODO: (Low) think about memory_order
 }