|
VLink
2.0.0
A high-performance communication middleware
|
Multi-threaded variant of MessageLoop that forwards tasks to an internal ThreadPool.
More...
Go to the source code of this file.
Classes | |
| class | vlink::MultiLoop |
MessageLoop subclass that forwards every task to an internal ThreadPool. More... | |
Namespaces | |
| vlink | |
Multi-threaded variant of MessageLoop that forwards tasks to an internal ThreadPool.
MultiLoop reuses every MessageLoop posting API but offloads execution to a pool of worker threads. The dispatcher thread still dequeues tasks; instead of running each task inline it hands them to the worker pool through the on_task_changed hook. Callers post via post_task / exec_task exactly as with a single-threaded loop.
ThreadPool)Forwarded tasks are submitted to the pool's single shared queue. Whichever worker is idle dequeues the next task, woken by the pool's condition variable. There is no round-robin, least-loaded, or hash-based worker selection: cross-worker ordering and thread affinity are not guaranteed.
* post_task / exec_task * | * v * +---------------------------------+ * | MessageLoop queue | * +----------------+----------------+ * | * v * +---------------------------------+ * | dispatcher thread | * +-------+--------+--------+-------+ * | | | * v v v * +-------+ +-------+ +-------+ * | Wkr 1 | | Wkr 2 | | Wkr N | * +-------+ +-------+ +-------+ *
MessageLoop is_in_same_thread returns true for the dispatcher and every worker thread.on_begin / on_end are still invoked once on the dispatcher; they construct and tear down the internal pool.MessageLoop::on_task_changed runs the callback inline on the dispatcher.MultiLoop fire as queue tasks; the dispatcher forwards them to a worker. The destructor is defaulted; always call quit and wait_for_quit before destruction.