#include <iostream>
struct trace_msg
{
std::string m_what;
std::thread::id m_thread_id;
};
{
public:
logger_actor( context_t ctx ) :
so_5::agent_t{ std::move(ctx) }
{
.
event( [](mhood_t<trace_msg> cmd ) {
std::cout << cmd->m_thread_id << ": (" << cmd->m_who
<< ") " << cmd->m_what << std::endl;
} );
}
};
} );
}
{
&agent, std::move(what), std::this_thread::get_id() );
}
const std::chrono::milliseconds sleeping_time{ 200 };
{
public :
A( context_t ctx ) :
so_5::agent_t{ ctx }
{
.
event( [
this]( mhood_t<M1> ) {
trace( *this, "A.e1 started" );
std::this_thread::sleep_for( sleeping_time );
trace( *this, "A.e1 finished" );
},
.event( [this]( mhood_t<M3> ) {
trace( *this, "A.e3 started" );
std::this_thread::sleep_for( sleeping_time );
trace( *this, "A.e3 finished" );
} )
}
};
{
public :
B( context_t ctx ) :
so_5::agent_t{ ctx }
{
.
event( [
this]( mhood_t<M2> ) {
trace( *this, "B.e2 started" );
std::this_thread::sleep_for( sleeping_time );
trace( *this, "B.e2 finished" );
},
}
};
{
create_logger( env );
pool_disp::make_dispatcher( env, 4 ).binder(
pool_disp::bind_params_t{}.fifo( fifo_type ) ),
{
} );
} );
}
int main()
{
try
{
std::cout << "cooperation FIFO..." << std::endl;
std::cout << "individual FIFO..." << std::endl;
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
subscription_bind_t so_subscribe(const mbox_t &mbox_ref)
Initiate subscription.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
mbox_t create_mbox()
Create an anonymous MPMC mbox.
void stop() noexcept
Send a shutdown signal to the Run-Time.
decltype(auto) introduce_coop(Args &&... args)
Helper method for simplification of cooperation creation and registration.
A base class for agent signals.
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t & >::type event(Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe)
Make subscription to the message.
Advanced thread pool dispatcher.
fifo_t
Type of FIFO mechanism for agent's demands.
@ cooperation
A FIFO for demands for all agents from the same cooperation.
@ individual
A FIFO for demands only for one agent.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
const thread_safety_t thread_safe
Shorthand for thread safety indicator.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.