Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Mantid::Kernel::ThreadScheduler Class Referenceabstract

The ThreadScheduler object defines how tasks are allocated to threads and in what order. More...

#include <ThreadScheduler.h>

Inheritance diagram for Mantid::Kernel::ThreadScheduler:
Mantid::Kernel::ThreadSchedulerFIFO Mantid::Kernel::ThreadSchedulerLargestCost Mantid::Kernel::ThreadSchedulerMutexes Mantid::Kernel::ThreadSchedulerLIFO

Public Member Functions

virtual void abort (std::runtime_error exception)
 Signal to the scheduler that a task is complete.
 
virtual void clear ()=0
 Empty out the queue.
 
virtual bool empty ()=0
 Returns true if the queue is empty.
 
virtual void finished (Task *task, size_t threadnum)
 Signal to the scheduler that a task is complete.
 
bool getAborted ()
 Returns true if the execution was aborted.
 
std::runtime_error getAbortException ()
 Returns the exception that was caught, if any.
 
bool hasBusyThreads () const
 Returns true if any thread is busy.
 
void markBusy ()
 Mark a thread as busy.
 
void markIdle ()
 Mark a thread as no longer busy. See markBusy().
 
virtual std::shared_ptr< Task > pop (size_t threadnum)=0
 Retrieves the next Task to execute.
 
virtual void push (std::shared_ptr< Task > newTask)=0
 Add a Task to the queue.
 
virtual size_t size ()=0
 Returns the size of the queue.
 
 ThreadScheduler ()
 Constructor.
 
double totalCost ()
 Returns the total cost of all Task's in the queue.
 
double totalCostExecuted ()
 Returns the total cost of all Task's in the queue.
 
virtual ~ThreadScheduler ()=default
 Destructor.
 

Protected Attributes

bool m_aborted
 The run was aborted due to an exception.
 
std::runtime_error m_abortException
 The exception that aborted the run.
 
double m_cost
 Total cost of all tasks.
 
double m_costExecuted
 Accumulated cost of tasks that have been executed (popped)
 
std::atomic< size_t > m_numBusyThreads {0}
 Number of threads that are getting or running a task.
 
std::mutex m_queueLock
 Mutex to prevent simultaneous access to the queue.
 

Detailed Description

The ThreadScheduler object defines how tasks are allocated to threads and in what order.

It holds the queue of tasks.

Author
Janik Zikovsky, SNS
Date
Feb 7, 2011

Definition at line 33 of file ThreadScheduler.h.

Constructor & Destructor Documentation

◆ ThreadScheduler()

Mantid::Kernel::ThreadScheduler::ThreadScheduler ( )
inline

Constructor.

Definition at line 37 of file ThreadScheduler.h.

◆ ~ThreadScheduler()

virtual Mantid::Kernel::ThreadScheduler::~ThreadScheduler ( )
virtualdefault

Destructor.

Member Function Documentation

◆ abort()

virtual void Mantid::Kernel::ThreadScheduler::abort ( std::runtime_error  exception)
inlinevirtual

Signal to the scheduler that a task is complete.

The scheduler may release mutexes, etc.

Parameters
exception:: the exception that aborted the run.

Definition at line 72 of file ThreadScheduler.h.

Referenced by Mantid::Kernel::ThreadPoolRunnable::run().

◆ clear()

virtual void Mantid::Kernel::ThreadScheduler::clear ( )
pure virtual

◆ empty()

virtual bool Mantid::Kernel::ThreadScheduler::empty ( )
pure virtual

◆ finished()

virtual void Mantid::Kernel::ThreadScheduler::finished ( Task *  task,
size_t  threadnum 
)
inlinevirtual

Signal to the scheduler that a task is complete.

Parameters
task:: the Task that was completed.
threadnum:: Thread ID that launched the task

Reimplemented in Mantid::Kernel::ThreadSchedulerMutexes.

Definition at line 61 of file ThreadScheduler.h.

References UNUSED_ARG.

Referenced by Mantid::Kernel::ThreadPoolRunnable::run().

◆ getAborted()

bool Mantid::Kernel::ThreadScheduler::getAborted ( )
inline

Returns true if the execution was aborted.

Definition at line 103 of file ThreadScheduler.h.

◆ getAbortException()

std::runtime_error Mantid::Kernel::ThreadScheduler::getAbortException ( )
inline

Returns the exception that was caught, if any.

Definition at line 100 of file ThreadScheduler.h.

◆ hasBusyThreads()

bool Mantid::Kernel::ThreadScheduler::hasBusyThreads ( ) const
inline

Returns true if any thread is busy.

A running task may still add tasks to the queue, so threads should not exit while this is true.

Definition at line 117 of file ThreadScheduler.h.

Referenced by Mantid::Kernel::ThreadPoolRunnable::run().

◆ markBusy()

void Mantid::Kernel::ThreadScheduler::markBusy ( )
inline

Mark a thread as busy.

A thread calls this before asking for a task and calls markIdle() once it has none, or once the task it got has finished.

Definition at line 109 of file ThreadScheduler.h.

◆ markIdle()

void Mantid::Kernel::ThreadScheduler::markIdle ( )
inline

Mark a thread as no longer busy. See markBusy().

Definition at line 112 of file ThreadScheduler.h.

◆ pop()

virtual std::shared_ptr< Task > Mantid::Kernel::ThreadScheduler::pop ( size_t  threadnum)
pure virtual

Retrieves the next Task to execute.

Parameters
threadnum:: ID of the calling thread.
Returns
a Task pointer to execute.

Implemented in Mantid::Kernel::ThreadSchedulerFIFO, Mantid::Kernel::ThreadSchedulerLIFO, Mantid::Kernel::ThreadSchedulerLargestCost, and Mantid::Kernel::ThreadSchedulerMutexes.

Referenced by Mantid::Kernel::ThreadPoolRunnable::run().

◆ push()

virtual void Mantid::Kernel::ThreadScheduler::push ( std::shared_ptr< Task >  newTask)
pure virtual

◆ size()

virtual size_t Mantid::Kernel::ThreadScheduler::size ( )
pure virtual

◆ totalCost()

double Mantid::Kernel::ThreadScheduler::totalCost ( )
inline

Returns the total cost of all Task's in the queue.

Definition at line 92 of file ThreadScheduler.h.

◆ totalCostExecuted()

double Mantid::Kernel::ThreadScheduler::totalCostExecuted ( )
inline

Returns the total cost of all Task's in the queue.

Definition at line 96 of file ThreadScheduler.h.

Member Data Documentation

◆ m_aborted

bool Mantid::Kernel::ThreadScheduler::m_aborted
protected

The run was aborted due to an exception.

Definition at line 129 of file ThreadScheduler.h.

◆ m_abortException

std::runtime_error Mantid::Kernel::ThreadScheduler::m_abortException
protected

The exception that aborted the run.

Definition at line 127 of file ThreadScheduler.h.

◆ m_cost

double Mantid::Kernel::ThreadScheduler::m_cost
protected

Total cost of all tasks.

Definition at line 121 of file ThreadScheduler.h.

Referenced by Mantid::Kernel::ThreadSchedulerMutexes::clear(), and Mantid::Kernel::ThreadSchedulerMutexes::push().

◆ m_costExecuted

double Mantid::Kernel::ThreadScheduler::m_costExecuted
protected

Accumulated cost of tasks that have been executed (popped)

Definition at line 123 of file ThreadScheduler.h.

Referenced by Mantid::Kernel::ThreadSchedulerMutexes::clear().

◆ m_numBusyThreads

std::atomic<size_t> Mantid::Kernel::ThreadScheduler::m_numBusyThreads {0}
protected

Number of threads that are getting or running a task.

Definition at line 131 of file ThreadScheduler.h.

◆ m_queueLock

std::mutex Mantid::Kernel::ThreadScheduler::m_queueLock
protected

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