libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
fly::task::TaskManager Class Reference

#include <task_manager.hpp>

Inheritance diagram for fly::task::TaskManager:
Collaboration diagram for fly::task::TaskManager:

Public Member Functions

bool start ()
 
bool stop ()
 

Static Public Member Functions

static std::shared_ptr< TaskManagercreate (std::uint32_t thread_count)
 

Friends

class TaskRunner
 

Detailed Description

Class to manage a pool of threads for executing tasks posted by any task runner. Also manages a timer thread to hold delayed tasks until their scheduled time.

The task manager makes no guarantee on the order of task execution; when a task is given to the task manager, it will be executed as soon as a worker thread is available. Instead, ordering is controlled by the task runners. A task runner may hold on to a task in accordance with its defined behavior until it is ready for the task manager to execute the task.

Author
Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
Version
August 12, 2018

Member Function Documentation

◆ create()

std::shared_ptr< TaskManager > fly::task::TaskManager::create ( std::uint32_t  thread_count)
static

Create and start a task manager.

Parameters
thread_countSize of the thread pool for the task manager to own.
Returns
The created task manager.

◆ start()

bool fly::task::TaskManager::start ( )

Create the worker threads and timer thread.

Returns
True if the threads were created in this invocation.

◆ stop()

bool fly::task::TaskManager::stop ( )

Destroy the worker threads and timer thread, blocking until the threads exit. This must be eplicitly called from the same thread that started the task manager.

TODO: TaskManager should be created as a unique_ptr so it can be started and stopped in an RAII fashion. It cannot be stopped from the destructor because a task thread may be the last owner of a shared_ptr to this task manager. In that case, when that shared_ptr is destroyed, the destructor would call stop, resulting in the task thread trying to join itself.

Returns
True if the threads were destroyed in this invocation.

The documentation for this class was generated from the following files: