#include <algorithm>
#include <iostream>
#include <string>
{
receive( from( command_ch ).handle_all(), [&]( string str ) {
this_thread::sleep_for( chrono::milliseconds( 10 * str.size() ) );
reverse( str.begin(), str.end() );
} );
}
{
receive( from( command_ch ).handle_all(), [&]( string str ) {
this_thread::sleep_for( chrono::milliseconds( 5 * str.size() * 2 ) );
} );
}
void demo()
{
vector< string > strings{ "one", "two", "three", "four" };
thread reverse_thread;
thread doubler_thread;
reverse_cmd_ch, reverse_reply_ch );
reverse_thread = thread{ reverse_worker, reverse_cmd_ch, reverse_reply_ch };
auto reverse_it = strings.begin();
doubler_cmd_ch, doubler_reply_ch );
doubler_thread = thread{ doubler_worker, doubler_cmd_ch, doubler_reply_ch };
auto doubler_it = strings.begin();
cout << "reverse_result: " << v << endl;
if( reverse_it != strings.end() )
else
} ),
cout << "doubler_result: " << v << endl;
if( doubler_it != strings.end() )
else
} ) );
}
int main()
{
try
{
demo();
}
catch( const exception & ex )
{
cerr << "Error: " << ex.what() << endl;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
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_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.
mchain_select_params_t< mchain_props::msg_count_status_t::undefined > from_all()
Helper function for creation of mchain_select_params instance with default values.
mchain_select_result_t select(const mchain_select_params_t< Msg_Count_Status > ¶ms, Cases &&... cases)
An advanced form of multi chain select.
void close_drop_content(Exceptions_Control exceptions_control, const mchain_t &ch) noexcept(noexcept(details::should_terminate_if_throws_t< Exceptions_Control >::value))
Helper function for closing a message chain with dropping all its content.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
mchain_props::select_case_unique_ptr_t receive_case(mchain_t chain, Handlers &&... handlers)
A helper for creation of select_case object for one multi chain select.
constexpr exceptions_enabled_t exceptions_enabled
Value that indicates that exceptions are enabled.
void close_retain_content(Exceptions_Control exceptions_control, const mchain_t &ch) noexcept(noexcept(details::should_terminate_if_throws_t< Exceptions_Control >::value))
Helper function for closing a message chain with retaining all its content.