All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Thread Class Referenceabstract

#include <UT_Thread.h>

+ Inheritance diagram for UT_Thread:


class  DisableGlobalControl
class  ThreadingDisabledScope

Public Types

enum  State { ThreadIdle, ThreadRunning }
enum  SpinMode { ThreadSingleRun, ThreadLowUsage }
using TerminateFunc ) = void(*)(

Public Member Functions

virtual ~UT_Thread ()
virtual bool startThread (UTthreadFunc func, void *data, int stacksize)=0
bool startThread (UTthreadFunc func, void *data)
virtual void threadStarted ()
virtual void threadEnded ()
virtual int isResourceHog () const
virtual State getState ()
virtual SpinMode getSpinMode ()
virtual void waitForState (State desired)=0
virtual void setSpinMode (SpinMode spin_mode)
virtual void killThread ()=0
virtual int suspendThread ()=0
virtual int restartThread ()=0
int isActive ()
virtual int64 getMemoryUsage (bool inclusive) const =0
 NOTE: This level doesn't own any data apart from itself. More...

Static Public Member Functions

static UT_ThreadallocThread (SpinMode spin_mode, bool uses_tbb=true)
static int getNumProcessors ()
static int activeThreadCount ()
 This is only valid in debug builds. More...
static void resetNumProcessors ()
static ut_thread_id_t getMyThreadId ()
static ut_thread_id_t getMainThreadId ()
static int getMainSequentialThreadId ()
static int isMainThread ()
static bool isUTThreadCurrent ()
static bool isThreadingEnabled ()
static bool setThreadingEnabled (bool will_be_enabled)
static void pause (uint cycles)
static void yield (bool higher_only=false)
static int getMySequentialThreadIndex ()
static void configureMaxThreads (int maxthreads=0)
static void configureThreadStackSize (int stacksize)
static bool isMaxThreadsConfigured ()
 Returns true if configureMaxThreads() has been called at least once. More...
static bool minimizeThisThreadPriority ()
static TerminateFunc getTaskSchedulerExitCallback ()

Protected Member Functions

virtual int waitThread (int block=1)=0
virtual int isValid ()
void killIdle ()
virtual void setState (State state)=0
 UT_Thread (SpinMode spin_mode, bool uses_tbb)

Static Protected Member Functions

static voidthreadWrapper (void *data)

Protected Attributes

volatile State myState
SpinMode mySpinMode
UTthreadFunc myCallback
const UT_TaskScopemyTaskScope
bool myUsesTBB

Detailed Description

Definition at line 59 of file UT_Thread.h.

Member Typedef Documentation

using UT_Thread::TerminateFunc = void (*)(

Return function pointer to terminate task scheduler that is activated by configureMaxThreads(). This function should called prior to exit() in order to avoid possible deadlocks when the process exits. Note that multiple calls to the termination function are handled by only terminating the first time. After that, no task scheduling is allowed.

Definition at line 246 of file UT_Thread.h.

Member Enumeration Documentation


Definition at line 80 of file UT_Thread.h.


Definition at line 69 of file UT_Thread.h.

Constructor & Destructor Documentation

virtual UT_Thread::~UT_Thread ( )
UT_Thread::UT_Thread ( SpinMode  spin_mode,
bool  uses_tbb 

Member Function Documentation

static int UT_Thread::activeThreadCount ( )

This is only valid in debug builds.

static UT_Thread* UT_Thread::allocThread ( SpinMode  spin_mode,
bool  uses_tbb = true 

Allocate a new thread

spin_modeUse ThreadSingleRun to have it exit when the thread callback is finished. Otherwise, ThreadLowUsage will cause the thread to loop back and wait for more startThread() calls to run different thread callbacks in the same thread.
uses_tbbLeave at true unless you absolutely know that no TBB tasks will be spawned in thread callbacks.
static void UT_Thread::configureMaxThreads ( int  maxthreads = 0)

Configure the global number of tasks used by the system

  • The default value of 0 uses the number of logical cores on the system
  • A negative value wraps it from the number of logical cores. eg. -1 will use all cores except for 1.
  • If the negative value exceeds the number of logical cores, it is clamped to a value of 1.
    Only call this in the main thread when there are no tasks active.
    This function is NOT thread-safe.
static void UT_Thread::configureThreadStackSize ( int  stacksize)

Configure the default stack size for threads

  • A value of 0 uses the stack size of the main thread
  • A value larger than 0 will use that specific stack size
    Only call this in the main thread when there are no tasks active.
    This function is NOT thread-safe.
static int UT_Thread::getMainSequentialThreadId ( )
static ut_thread_id_t UT_Thread::getMainThreadId ( )
virtual int64 UT_Thread::getMemoryUsage ( bool  inclusive) const
pure virtual

NOTE: This level doesn't own any data apart from itself.

Implemented in UT_NullThread.

static int UT_Thread::getMySequentialThreadIndex ( )

This function has been deprecated. Use SYS_SequentialThreadIndex::get() or SYSgetSTID instead.

Definition at line 191 of file UT_Thread.h.

static ut_thread_id_t UT_Thread::getMyThreadId ( )
static int UT_Thread::getNumProcessors ( )
virtual SpinMode UT_Thread::getSpinMode ( )
virtual State UT_Thread::getState ( )
static TerminateFunc UT_Thread::getTaskSchedulerExitCallback ( )
int UT_Thread::isActive ( )

Definition at line 288 of file UT_Thread.h.

static int UT_Thread::isMainThread ( )

Definition at line 116 of file UT_Thread.h.

static bool UT_Thread::isMaxThreadsConfigured ( )

Returns true if configureMaxThreads() has been called at least once.

virtual int UT_Thread::isResourceHog ( ) const
static bool UT_Thread::isThreadingEnabled ( )

Returns true iff the current thread is allowed to create more tasks. This is sometimes disabled, to avoid needing to create a UT_TaskArena for small cases that won't get much benefit from threading. This should be checked by anything using tbb::parallel_for, tbb::parallel_invoke, or anything else creating TBB tasks.

static bool UT_Thread::isUTThreadCurrent ( )

Returns true if the current thread is a UT_Thread. Returns false if the current thread is either the main thread or a TBB thread.

virtual int UT_Thread::isValid ( )
void UT_Thread::killIdle ( )
virtual void UT_Thread::killThread ( )
pure virtual

Implemented in UT_NullThread.

static bool UT_Thread::minimizeThisThreadPriority ( )

Sets the current thread to minimum priority according to the rules of the platform. This function fails if called on a thread that is not a running UT_Thread. Returns true if the operation was successful, otherwise returns false.

static void UT_Thread::pause ( uint  cycles)

Definition at line 155 of file UT_Thread.h.

static void UT_Thread::resetNumProcessors ( )

Reset the number of threads that is used by Houdini. This will reread the HOUDINI_MAXTHREADS setting.

There should be no active tasks when this is called.
Only call this from the MAIN THREAD!
virtual int UT_Thread::restartThread ( )
pure virtual

Implemented in UT_NullThread.

virtual void UT_Thread::setSpinMode ( SpinMode  spin_mode)
virtual void UT_Thread::setState ( State  state)
protectedpure virtual

Implemented in UT_NullThread.

static bool UT_Thread::setThreadingEnabled ( bool  will_be_enabled)

This is used to disable (false) threading for the current thread, to avoid needing to create a UT_TaskArena for small cases that won't get much benefit from threading. It returns if it was enabled before. It is also used to re-enable (true) threading for the current thread.

virtual bool UT_Thread::startThread ( UTthreadFunc  func,
void data,
int  stacksize 
pure virtual

Implemented in UT_NullThread.

bool UT_Thread::startThread ( UTthreadFunc  func,
void data 
virtual int UT_Thread::suspendThread ( )
pure virtual

Implemented in UT_NullThread.

virtual void UT_Thread::threadEnded ( )
virtual void UT_Thread::threadStarted ( )
static void* UT_Thread::threadWrapper ( void data)
virtual void UT_Thread::waitForState ( State  desired)
pure virtual

Implemented in UT_NullThread.

virtual int UT_Thread::waitThread ( int  block = 1)
protectedpure virtual

Implemented in UT_NullThread.

static void UT_Thread::yield ( bool  higher_only = false)

Member Data Documentation

UTthreadFunc UT_Thread::myCallback

Definition at line 314 of file UT_Thread.h.

void* UT_Thread::myCBData

Definition at line 315 of file UT_Thread.h.

SpinMode UT_Thread::mySpinMode

Definition at line 313 of file UT_Thread.h.

volatile State UT_Thread::myState

Definition at line 312 of file UT_Thread.h.

const UT_TaskScope* UT_Thread::myTaskScope

Definition at line 317 of file UT_Thread.h.

bool UT_Thread::myUsesTBB

Definition at line 318 of file UT_Thread.h.

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