SObjectizer 5.8
Loading...
Searching...
No Matches
so-5.5.16: mchains use MPMC queue inside

Since v.5.5.16 mchains use Multi-Producer/Multi-Consumer queue inside. It makes possible to use the same mchain in several parallel receive on different threads. It could be used for simple load balancing scheme, for example:

void worker_thread(so_5::mchain_t ch)
{
// Handle all messages until mchain will be closed.
receive(from(ch), handler1, handler2, handler3, ...);
}
...
// Message chain for passing messages to worker threads.
auto ch = create_mchain(env);
// Worker thread.
thread worker1{worker_thread, ch};
thread worker2{worker_thread, ch};
thread worker3{worker_thread, ch};
// Send messages to workers.
while(has_some_work())
{
...
}
// Close chain and finish worker threads.
worker3.join();
worker2.join();
worker1.join();
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
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.
Definition mchain.hpp:708