#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
{
public :
{}
{
}
{
if( m_next )
so_5::send< msg_your_turn >( m_next );
else
} );
}
private :
};
{
public :
a_coordinator_t( context_t ctx, unsigned int iterations )
, m_remaining_iterations( iterations )
{}
{
--m_remaining_iterations;
show_remaining_iterations();
if( m_remaining_iterations )
create_new_child_coop();
else
{
std::cout << "no more iterations left, finishing..." << std::endl;
}
} );
}
{
show_remaining_iterations();
create_new_child_coop();
}
private :
unsigned int m_remaining_iterations;
void show_remaining_iterations() const
{
std::cout << m_remaining_iterations << ": iterations left...\r"
<< std::flush;
}
void create_new_child_coop()
{
*this,
disp->binder() );
coop->add_dereg_notificator(
auto first_mbox = fill_coop( *coop );
so_5::send< a_chain_member_t::msg_your_turn >( first_mbox );
}
{
std::vector< so_5::mbox_t > mboxes;
std::vector< a_chain_member_t * > agents;
{
agents.push_back( a );
mboxes.push_back( a->so_direct_mbox() );
}
agents[ i ]->set_next( mboxes[ i + 1 ] );
return mboxes[ 0 ];
}
};
unsigned int detect_iteration_count( int argc, char ** argv )
{
unsigned int r = 5000;
if( 2 == argc )
{
auto a = std::atoi( argv[ 1 ] );
if( a > 0 )
r = static_cast< unsigned int >( a );
else
throw std::invalid_argument(
"invalid iteration count: " + std::to_string( a ) );
}
return r;
}
int main( int argc, char ** argv )
{
try
{
const auto iterations = detect_iteration_count( argc, argv );
env.
make_agent< a_coordinator_t >( iterations ) );
} );
return 0;
}
catch( const std::exception & x )
{
std::cerr << "*** Exception caught: " << x.what() << std::endl;
}
return 2;
}