Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::ThreadManager Class Referenceabstract

Platform-independent base class for running concurrent threads. More...

#include <geogram/basic/process.h>

Inheritance diagram for GEO::ThreadManager:
GEO::Counted GEO::MonoThreadingThreadManager

Public Member Functions

virtual void run_threads (ThreadGroup &threads)
 Runs a group of Threads. More...
 
virtual index_t maximum_concurrent_threads ()=0
 Gets the maximum number of possible concurrent threads. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Protected Member Functions

virtual void run_concurrent_threads (ThreadGroup &threads, index_t max_threads)=0
 Runs a group of Threads concurrently. More...
 
 ~ThreadManager () override
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Static Protected Member Functions

static void set_thread_id (Thread *thread, index_t id)
 Sets the id of a thread. More...
 
static void set_current_thread (Thread *thread)
 Specifies the current instance, used by current(). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Detailed Description

Platform-independent base class for running concurrent threads.

The ThreadManager manager provides a platform-independent abstract interface for running concurrent Threads and managing critical sections.

The ThreadManager is derived in multiple platform-specific or technology-specific implementations.

Platform-specific implementations:

  • POSIX Thread manager (Unix)
  • Windows Threads manager (Windows)
  • Windows ThreadPool manager (Windows)

Technology-specific implementations:

  • OpenMP-based manager

Which ThreadManager to use is determined at runtime by Process::initialize() according to the current platform or the current available technology.

Note
For internal use only.
See also
Process::set_thread_manager()

Definition at line 213 of file process.h.

Constructor & Destructor Documentation

◆ ~ThreadManager()

GEO::ThreadManager::~ThreadManager ( )
overrideprotected

ThreadManager destructor

Member Function Documentation

◆ maximum_concurrent_threads()

virtual index_t GEO::ThreadManager::maximum_concurrent_threads ( )
pure virtual

Gets the maximum number of possible concurrent threads.

Returns
The maximum number of possible concurrent threads allowed by this manager. It depends on the physical number of cores (including hyper-threading or not) and the technology implemented by this manager.
See also
Process::number_of_cores()

Implemented in GEO::MonoThreadingThreadManager.

◆ run_concurrent_threads()

virtual void GEO::ThreadManager::run_concurrent_threads ( ThreadGroup threads,
index_t  max_threads 
)
protectedpure virtual

Runs a group of Threads concurrently.

This start the concurrent execution of the threads contained in vector threads, using the given number of threads max_threads. The execution terminates when the last thread terminates.

Parameters
[in]threadsthe vector of threads to be executed.
[in]max_threadsmaximum number of threads allowed for this execution. It is always greater than one

Implemented in GEO::MonoThreadingThreadManager.

◆ run_threads()

virtual void GEO::ThreadManager::run_threads ( ThreadGroup threads)
virtual

Runs a group of Threads.

This start the execution of the threads contained in vector threads.

If the threads cannot be executed in a concurrent environment (multi-threading is disabled or the number of maximum threads is 1), then the threads are executed sequentially. Otherwise the function run_concurrent_threads() is called to execute the threads concurrently. The execution terminates when the last thread terminates.

Parameters
[in]threadsthe vector of threads to be executed.
See also
maximum_concurrent_threads()
run_concurrent_threads()
Process::max_threads()

◆ set_current_thread()

static void GEO::ThreadManager::set_current_thread ( Thread thread)
inlinestaticprotected

Specifies the current instance, used by current().

Stores the specified thread in the thread-local-storage static variable so that current() can retrieve it. Should be called by the ThreadManager right before launching the threads.

Parameters
[in]threada pointer to the thread currently executed

Definition at line 281 of file process.h.

◆ set_thread_id()

static void GEO::ThreadManager::set_thread_id ( Thread thread,
index_t  id 
)
inlinestaticprotected

Sets the id of a thread.

This function is called right before starting the threads. Each thread will have an id in [0, N-1] where N denotes the number of running threads.

Parameters
[in]threadthe thread
[in]idthe id

Definition at line 269 of file process.h.


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