class thread_state final
{
std::chrono::milliseconds pause_{ 750 };
bool must_stop_{ false };
public :
bool must_stop() const { return must_stop_; }
template<typename Reply>
{
if( pause_ > std::chrono::milliseconds(5) )
{
pause_ = std::chrono::milliseconds(
static_cast< decltype(pause_.count()) >(
double(pause_.count()) / 1.5) );
}
else
{
must_stop_ = true;
}
}
};
{
thread_state state;
from(recv_chain).handle_all().stop_on( [&state]{
return state.must_stop(); } ),
std::cout << "Tick!" << std::endl;
state.reply_or_stop< tack >( write_chain );
},
std::cout << "Tack!" << std::endl;
state.reply_or_stop< tick >( write_chain );
} );
}
{
return env_params;
}
int main()
{
std::thread second_thread;
second_thread = std::thread( thread_body, ch2, ch1 );
thread_body( ch1, ch2 );
return 0;
}
A helper header file for including all public SObjectizer stuff.
Parameters for the SObjectizer Environment initialization.
const environment_infrastructure_factory_t & infrastructure_factory() const
Get the current environment infrastructure factory.
A message wrapped to be used as type of argument for event handlers.
A base class for agent signals.
environment_infrastructure_factory_t factory()
A factory for creation of simple thread-safe single-thread environment infrastructure object with def...
thread_auto_join_details::auto_joiner_t< 1+sizeof...(Tail) > auto_join(std::thread &first_thread, Tail &&... tail)
Helper function for creation of automatic joiner of std::threads.
mchain_receive_params_t< mchain_props::msg_count_status_t::undefined > from(mchain_t chain)
A helper function for simplification of creation of mchain_receive_params instance.
mchain_auto_close_details::auto_closer_t< sizeof...(Tail) > auto_close_drop_content(Tail &&... tail)
Helper function for automatic closing of mchains with dropping their content.
mchain_t create_mchain(environment_t &env)
Create size-unlimited chain.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
void send_delayed(Target &&target, std::chrono::steady_clock::duration pause, Args &&... args)
A utility function for creating and delivering a delayed message to the specified destination.
mchain_receive_result_t receive(const mchain_receive_params_t< Msg_Count_Status > ¶ms, Handlers &&... handlers)
Advanced version of receive from mchain.