You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A new noexcept method push_evt_wakeup in event_queue_t?
#118
An agent with enabled C++20 coroutines support works a bit differently than ordinary agents.
When a message is sent to an ordinary agent an execution_demand_t is formed and this demand is stored in the dispatcher's demand queue. If several messages are sent for one agent at the same time there will be several execution demands in the dispatcher's queue -- one demand for one message.
But if C++20 coroutines support enabled then all "normal" execution demands are buffered in the local agent's queue. When this queue is empty and the first execution demand arrives then a special "wakeup" demand is stored in the dispatcher queue. If several messages are sent to such an agent at the same time then there will be several "normal" execution demands in the local agent's queue, but only one special "wakeup" demand in the dispatcher's queue.
When the dispatcher extracts the "wakeup" demand it calls the agent's demand handler the usual way. This demand handler dequeues and processes "normal" demands from the agent's local queue (up to N "normal" demands at once).
This scheme allows to pause the processing of "normal" demands in a case when C++20 coroutine has been started and suspended.
This approach is simple, but it has a couple of weak points. One of them is the usage of two queues (one is the local agent's queue, the second is the dispatcher queue). Another one is the moment of pushing the "wakeup" demand to the dispatcher's queue. Ordinary event_queue_t::push is used in the current implementation at v.5.8.7.
But event_queue_t::push may throw. For example, event_queue_t::push may throw std::bad_alloc if the dispatcher uses dynamic memory for the demand queue.
If event_queue_t::push throws for "wakeup" demand then the demand will be lost and it will stop processing of agent's demands. This is unacceptable and because of that such calls are wrapped into noexcept code blocks. It means that if event_queue_t::push for "wakeup" demand throws then the whole application will be terminated.
This case is very similar to "evt_finish" demand. If pushing of "evt_finish" demand fails with an exception then normal work can't be continued and the whole application is terminated. To avoid such terminations a couple of special dispatchers were introduced some time ago: nef_one_thread and nef_thread_pool. Those dispatchers reserve additional memory for "evt_finish" demands and use special intrusive demand queues. It allows us to guarantee that "evt_finish" will be enqueued without exceptions.
But introduction of nef_one_thread and nef_thread_pool dispatchers required changing the event_queue_t interface. Initially this interface had only one push method, but now it has three separate methods: push, push_evt_start and non-throwing push_evt_finish.
So I am thinking about another extension of the event_queue_t interface -- addition of a non-throwing push_evt_wakeup method. In 5.8 branch this method will have the default implementation:
virtualvoidpush_evt_demand( execution_demand_t demand ) noexcept
{
// Just delegate the work to ordinary `push`. If `push` throws the whole// application will be aborted.this->push( std::move(demand) );
}
But in the 5.9 branch it will become a pure virtual method.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
An agent with enabled C++20 coroutines support works a bit differently than ordinary agents.
When a message is sent to an ordinary agent an
execution_demand_tis formed and this demand is stored in the dispatcher's demand queue. If several messages are sent for one agent at the same time there will be several execution demands in the dispatcher's queue -- one demand for one message.But if C++20 coroutines support enabled then all "normal" execution demands are buffered in the local agent's queue. When this queue is empty and the first execution demand arrives then a special "wakeup" demand is stored in the dispatcher queue. If several messages are sent to such an agent at the same time then there will be several "normal" execution demands in the local agent's queue, but only one special "wakeup" demand in the dispatcher's queue.
When the dispatcher extracts the "wakeup" demand it calls the agent's demand handler the usual way. This demand handler dequeues and processes "normal" demands from the agent's local queue (up to N "normal" demands at once).
This scheme allows to pause the processing of "normal" demands in a case when C++20 coroutine has been started and suspended.
This approach is simple, but it has a couple of weak points. One of them is the usage of two queues (one is the local agent's queue, the second is the dispatcher queue). Another one is the moment of pushing the "wakeup" demand to the dispatcher's queue. Ordinary
event_queue_t::pushis used in the current implementation at v.5.8.7.But
event_queue_t::pushmay throw. For example,event_queue_t::pushmay throwstd::bad_allocif the dispatcher uses dynamic memory for the demand queue.If
event_queue_t::pushthrows for "wakeup" demand then the demand will be lost and it will stop processing of agent's demands. This is unacceptable and because of that such calls are wrapped intonoexceptcode blocks. It means that ifevent_queue_t::pushfor "wakeup" demand throws then the whole application will be terminated.This case is very similar to "evt_finish" demand. If pushing of "evt_finish" demand fails with an exception then normal work can't be continued and the whole application is terminated. To avoid such terminations a couple of special dispatchers were introduced some time ago: nef_one_thread and nef_thread_pool. Those dispatchers reserve additional memory for "evt_finish" demands and use special intrusive demand queues. It allows us to guarantee that "evt_finish" will be enqueued without exceptions.
But introduction of nef_one_thread and nef_thread_pool dispatchers required changing the
event_queue_tinterface. Initially this interface had only onepushmethod, but now it has three separate methods:push,push_evt_startand non-throwingpush_evt_finish.So I am thinking about another extension of the
event_queue_tinterface -- addition of a non-throwingpush_evt_wakeupmethod. In 5.8 branch this method will have the default implementation:But in the 5.9 branch it will become a pure virtual method.
All reactions