← API Reference Class

asge::concurrent::_internal::Worker

A thread pool worker that continuously drains jobs from a shared queue.

#include <ThreadPool.hpp>

Inherits from asge::concurrent::Thread.

Inheritance

classDiagram
    class N2["asge::concurrent::Thread"]
    class N1["asge::concurrent::_internal::Worker"]
    N2 <|-- N1
    click N2 href "classasge_1_1concurrent_1_1Thread.html"
    click N1 href "classasge_1_1concurrent_1_1__internal_1_1Worker.html"

Collaboration

classDiagram
    class N2["asge::concurrent::Thread"]
    class N1["asge::concurrent::_internal::Worker"]
    N2 <|-- N1
    click N2 href "classasge_1_1concurrent_1_1Thread.html"
    click N1 href "classasge_1_1concurrent_1_1__internal_1_1Worker.html"

Worker extends Thread with a single responsibility: loop over a shared job_queue, pop executor_pointer entries as they become available, and call Execute() on each. It holds no ownership over the queue — only a reference — so the ThreadPool that owns both the queue and the workers must ensure the queue outlives all workers.

Each Worker is assigned a unique human-readable name ("Worker_1", "Worker_2", ...) via a static counter, which aids debugging and profiling.

Workers are move-constructible to allow storage in a std::vector, but are non-copyable since they hold a mutable queue reference and manage a live thread.

Note

The static ID counter (s_Id) is not thread-safe. Workers are expected to be constructed sequentially during ThreadPool initialisation, not concurrently.

See also

ThreadPool — owns the queue and the worker vector.

See also

IExecuter — the interface each dequeued job implements.

Private Types

#using job_queue_ref = job_queue &private

Static Private Attributes

#static std::size_t s_Id {0}private

Private Attributes

#job_queue_ref m_JobQueueprivate

Private Member Functions

#virtual void Run(context_pointer &inCtx) overrideprivate

Implements the internal thread logic.

This method must implement only the internal thread logic inside the thread loop, which is instead managed outside the particular thread implementation. Therefore, all other conditions that might be return the thread execution must be specified in this method. To cancel the thread, the Cancel function on the context shall be called.

Overrides Run

Public Member Functions

#Worker(job_queue_ref inQueue, context_pointer inCtx)
#Worker(Worker &&)=default
#Worker & operator=(Worker &&)=default
#Worker(Worker const &)=delete
#Worker & operator=(Worker const &)=delete
#~Worker() override