c++-gtk-utils
Public Member Functions | List of all members
Cgu::Thread::TaskManager::IncHandle Class Reference

A scoped handle for exception safe incrementing of the maximum number of threads that a TaskManager object will run. More...

#include <c++-gtk-utils/task_manager.h>

Public Member Functions

 IncHandle (TaskManager &tm_)
 
 ~IncHandle ()
 

Detailed Description

A scoped handle for exception safe incrementing of the maximum number of threads that a TaskManager object will run.

See also
Thread::TaskManager

This class is for use where a task running on a TaskManager object is about to make a blocking call. It enables the task to increment in an exception safe way the maximum number of tasks which the TaskManager object will currently run in its thread pool to enable another thread to keep a core active, so that the number is automatically decremented again when the ThreadManager::IncHandle object has gone out of scope after the task has finished making blocking calls or something has thrown.

The documentation on Thread::TaskManager gives an example of its use.

This class is available since version 1.2.31 of the library.

Constructor & Destructor Documentation

◆ IncHandle()

Cgu::Thread::TaskManager::IncHandle::IncHandle ( TaskManager tm_)
inlineexplicit

This constructor calls TaskManager::change_max_threads() to increment the maximum number of threads a TaskManager object will currently run in its thread pool.

Parameters
tm_The TaskManager object whose maximum thread limit is to be incremented.
Exceptions
std::bad_allocIf tasks are currently queued for execution, a new thread will be started, so this exception may be thrown on starting the thread if memory is exhausted and the system throws in that case. (On systems with over-commit/lazy-commit combined with virtual memory (swap), it is rarely useful to check for memory exhaustion).
Cgu::Thread::TaskErrorIf tasks are currently queued for execution, a new thread will be started, so this exception may be thrown on starting the thread if it fails to start correctly (this would mean that memory is exhausted, the pthread thread limit has been reached or pthread has run out of other resources to start new threads).

Since 1.2.31

◆ ~IncHandle()

Cgu::Thread::TaskManager::IncHandle::~IncHandle ( )
inline

This destructor calls TaskManager::change_max_threads() to decrement the maximum number of threads a TaskManager object will currently run in its thread pool. It will not throw.

Since 1.2.31


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