cartobase 6.0.6
carto::ThreadedLoop Class Reference

#include <cartobase/thread/threadedLoop.h>

Public Member Functions

 ThreadedLoop (LoopContext *loopContext, int startIndex, int count, int maxThreadCount=0, float threadsByCpu=1.0f)
 
virtual ~ThreadedLoop ()
 
void setLoopContext (LoopContext *)
 This function is only useful in multiple run mode (endThreadsWhenDone false).
 
bool launch (bool resetGauge=true, bool resetCancel=true)
 run the loop to the end until all iterations are finished
 
void run ()
 run one iteration step. It normally calls the LoopContext diIt() method
 
void setEndThreadsWhenDone (bool x)
 Warning: it's possibly not safe to change this value from false to true after launch() has been called.
 
bool endThreadsWhenDone () const
 The loop can work in two modes: single run (endThreadsWhenDone() is true) or multiple runs (endThreadsWhenDone is false).
 
void setLoopCount (int n)
 
bool runSingleThreaded (bool resetGauge=true, bool resetCancel=true)
 

Detailed Description

Definition at line 48 of file threadedLoop.h.

Constructor & Destructor Documentation

◆ ThreadedLoop()

carto::ThreadedLoop::ThreadedLoop ( LoopContext * loopContext,
int startIndex,
int count,
int maxThreadCount = 0,
float threadsByCpu = 1.0f )

◆ ~ThreadedLoop()

virtual carto::ThreadedLoop::~ThreadedLoop ( )
virtual

Member Function Documentation

◆ endThreadsWhenDone()

bool carto::ThreadedLoop::endThreadsWhenDone ( ) const

The loop can work in two modes: single run (endThreadsWhenDone() is true) or multiple runs (endThreadsWhenDone is false).

  • In single run mode, launch() creates the needed number of threads, runs them to complete the loop, then destroys every thread.
  • In multiple runs mode, the first call to launch() creates the needed threads, but doesn't destroy them after the loop is finished. Each thread stays alive and blocks on a semaphore. When you call launch() again later for another run (possibly after changing the LoopContext), the existing threads will be re-used for the next loop, so the cost of destroying and creating threads again is avoided. All threads will be actually destroyed when the ThreadedLoop is deleted.

◆ launch()

bool carto::ThreadedLoop::launch ( bool resetGauge = true,
bool resetCancel = true )

run the loop to the end until all iterations are finished

◆ run()

void carto::ThreadedLoop::run ( )

run one iteration step. It normally calls the LoopContext diIt() method

◆ runSingleThreaded()

bool carto::ThreadedLoop::runSingleThreaded ( bool resetGauge = true,
bool resetCancel = true )

◆ setEndThreadsWhenDone()

void carto::ThreadedLoop::setEndThreadsWhenDone ( bool x)

Warning: it's possibly not safe to change this value from false to true after launch() has been called.

◆ setLoopContext()

void carto::ThreadedLoop::setLoopContext ( LoopContext * )

This function is only useful in multiple run mode (endThreadsWhenDone false).

Call it only between two runs, from the control thread (the thread running the loop).

◆ setLoopCount()

void carto::ThreadedLoop::setLoopCount ( int n)

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