Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Thread Class Reference

#include <Thread.h>

+ Inheritance diagram for Poco::Thread:
+ Collaboration diagram for Poco::Thread:

Classes

class  FunctorRunnable
 Creates and returns a unique id for a thread. More...
 

Public Types

enum  Priority {
  PRIO_LOWEST = PRIO_LOWEST_IMPL , PRIO_LOW = PRIO_LOW_IMPL , PRIO_NORMAL = PRIO_NORMAL_IMPL , PRIO_HIGH = PRIO_HIGH_IMPL ,
  PRIO_HIGHEST = PRIO_HIGHEST_IMPL
}
 Thread priorities. More...
 
enum  Policy { POLICY_DEFAULT = POLICY_DEFAULT_IMPL }
 
typedef ThreadImpl::TIDImpl TID
 
typedef void(* Callable) (void *)
 

Public Member Functions

 Thread ()
 
 Thread (const std::string &name)
 Creates a thread. Call start() to start it.
 
 ~Thread ()
 Creates a named thread. Call start() to start it.
 
int id () const
 Destroys the thread.
 
TID tid () const
 Returns the unique thread ID of the thread.
 
std::string name () const
 Returns the native thread ID of the thread.
 
std::string getName () const
 Returns the name of the thread.
 
void setName (const std::string &name)
 Returns the name of the thread.
 
void setPriority (Priority prio)
 Sets the name of the thread.
 
Priority getPriority () const
 
void setOSPriority (int prio, int policy=POLICY_DEFAULT)
 Returns the thread's priority.
 
int getOSPriority () const
 
void setStackSize (int size)
 
int getStackSize () const
 
void start (Runnable &target)
 
void start (Poco::SharedPtr< Runnable > pTarget)
 
void start (Callable target, void *pData=0)
 
template<class Functor >
void startFunc (const Functor &fn)
 Starts the thread with the given target and parameter.
 
template<class Functor >
void startFunc (Functor &&fn)
 Starts the thread with the given functor object or lambda.
 
void join ()
 
void join (long milliseconds)
 
bool tryJoin (long milliseconds)
 
bool isRunning () const
 
void wakeUp ()
 

Static Public Member Functions

static int getMinOSPriority (int policy=POLICY_DEFAULT)
 
static int getMaxOSPriority (int policy=POLICY_DEFAULT)
 
static bool trySleep (long milliseconds)
 Returns true if the thread is running.
 
static void sleep (long milliseconds)
 
static void yield ()
 
static Threadcurrent ()
 Yields cpu to other threads.
 
static TID currentTid ()
 

Protected Member Functions

ThreadLocalStoragetls ()
 Returns the native thread ID for the current thread.
 
void clearTLS ()
 Returns a reference to the thread's local storage.
 
std::string makeName ()
 Clears the thread's local storage.
 

Static Protected Member Functions

static int uniqueId ()
 Creates a unique name for a thread.
 

Private Member Functions

 Thread (const Thread &)
 
Threadoperator= (const Thread &)
 
- Private Member Functions inherited from Poco::ThreadImpl
 ThreadImpl ()
 
 ~ThreadImpl ()
 
TIDImpl tidImpl () const
 
void setPriorityImpl (int prio)
 
int getPriorityImpl () const
 
void setOSPriorityImpl (int prio, int policy=0)
 
int getOSPriorityImpl () const
 
void setStackSizeImpl (int size)
 
int getStackSizeImpl () const
 
void startImpl (SharedPtr< Runnable > pTarget)
 
void joinImpl ()
 
bool joinImpl (long milliseconds)
 
bool isRunningImpl () const
 
void createImpl (Entry ent, void *pData)
 
void threadCleanup ()
 

Private Attributes

int _id
 
std::string _name
 
ThreadLocalStorage_pTLS
 
Event _event
 
FastMutex _mutex
 

Friends

class ThreadLocalStorage
 
class PooledThread
 

Additional Inherited Members

- Private Types inherited from Poco::ThreadImpl
enum  Priority {
  PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST , PRIO_LOW_IMPL = THREAD_PRIORITY_BELOW_NORMAL , PRIO_NORMAL_IMPL = THREAD_PRIORITY_NORMAL , PRIO_HIGH_IMPL = THREAD_PRIORITY_ABOVE_NORMAL ,
  PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST
}
 
enum  Policy { POLICY_DEFAULT_IMPL = 0 }
 
typedef DWORD TIDImpl
 
typedef void(* Callable) (void *)
 
typedef unsigned(__stdcall * Entry) (void *)
 
- Static Private Member Functions inherited from Poco::ThreadImpl
static int getMinOSPriorityImpl (int policy)
 
static int getMaxOSPriorityImpl (int policy)
 
static void sleepImpl (long milliseconds)
 
static void yieldImpl ()
 
static ThreadImplcurrentImpl ()
 
static TIDImpl currentTidImpl ()
 
static unsigned __stdcall runnableEntry (void *pThread)
 

Detailed Description

This class implements a platform-independent wrapper to an operating system thread.

Every Thread object gets a unique (within its process) numeric thread ID. Furthermore, a thread can be assigned a name. The name of a thread can be changed at any time.

Definition at line 46 of file Thread.h.

Member Typedef Documentation

◆ Callable

typedef void(* Poco::ThreadImpl::Callable) (void *)

Definition at line 34 of file Thread_WIN32.h.

◆ TID

Definition at line 56 of file Thread.h.

Member Enumeration Documentation

◆ Policy

Enumerator
POLICY_DEFAULT 

Definition at line 70 of file Thread.h.

◆ Priority

Thread priorities.

Enumerator
PRIO_LOWEST 
PRIO_LOW 

The lowest thread priority.

PRIO_NORMAL 

A lower than normal thread priority.

PRIO_HIGH 

The normal thread priority.

PRIO_HIGHEST 

A higher than normal thread priority.

Definition at line 60 of file Thread.h.

Constructor & Destructor Documentation

◆ Thread() [1/3]

Poco::Thread::Thread ( )

◆ Thread() [2/3]

Poco::Thread::Thread ( const std::string & name)

Creates a thread. Call start() to start it.

◆ ~Thread()

Poco::Thread::~Thread ( )

Creates a named thread. Call start() to start it.

◆ Thread() [3/3]

Poco::Thread::Thread ( const Thread & )
private

Member Function Documentation

◆ clearTLS()

void Poco::Thread::clearTLS ( )
protected

Returns a reference to the thread's local storage.

◆ current()

Thread * Poco::Thread::current ( )
inlinestatic

Yields cpu to other threads.

Definition at line 334 of file Thread.h.

+ Here is the call graph for this function:

◆ currentTid()

Thread::TID Poco::Thread::currentTid ( )
inlinestatic

Returns the Thread object for the currently active thread. If the current thread is the main thread, 0 is returned.

Definition at line 376 of file Thread.h.

+ Here is the call graph for this function:

◆ getMaxOSPriority()

int Poco::Thread::getMaxOSPriority ( int policy = POLICY_DEFAULT)
inlinestatic

Returns the minimum operating system-specific priority value, which can be passed to setOSPriority() for the given policy.

Definition at line 358 of file Thread.h.

+ Here is the call graph for this function:

◆ getMinOSPriority()

int Poco::Thread::getMinOSPriority ( int policy = POLICY_DEFAULT)
inlinestatic

Returns the thread's priority, expressed as an operating system specific priority value.

May return 0 if the priority has not been explicitly set.

Definition at line 352 of file Thread.h.

+ Here is the call graph for this function:

◆ getName()

std::string Poco::Thread::getName ( ) const
inline

Returns the name of the thread.

Definition at line 308 of file Thread.h.

+ Here is the call graph for this function:

◆ getOSPriority()

int Poco::Thread::getOSPriority ( ) const
inline

Sets the thread's priority, using an operating system specific priority value. Use getMinOSPriority() and getMaxOSPriority() to obtain mininum and maximum priority values. Additionally, a scheduling policy can be specified. The policy is currently only used on POSIX platforms where the values SCHED_OTHER (default), SCHED_FIFO and SCHED_RR are supported.

Definition at line 346 of file Thread.h.

+ Here is the call graph for this function:

◆ getPriority()

Priority Poco::Thread::getPriority ( ) const

Sets the thread's priority.

Some platform only allow changing a thread's priority if the process has certain privileges.

◆ getStackSize()

int Poco::Thread::getStackSize ( ) const
inline

Sets the thread's stack size in bytes. Setting the stack size to 0 will use the default stack size. Typically, the real stack size is rounded up to the nearest page size multiple.

Definition at line 370 of file Thread.h.

+ Here is the call graph for this function:

◆ id()

int Poco::Thread::id ( ) const
inline

Destroys the thread.

Definition at line 294 of file Thread.h.

◆ isRunning()

bool Poco::Thread::isRunning ( ) const
inline

Waits for at most the given interval for the thread to complete. Returns true if the thread has finished, false otherwise.

Definition at line 316 of file Thread.h.

+ Here is the call graph for this function:

◆ join() [1/2]

void Poco::Thread::join ( )

◆ join() [2/2]

void Poco::Thread::join ( long milliseconds)

Waits until the thread completes execution. If multiple threads try to join the same thread, the result is undefined.

◆ makeName()

std::string Poco::Thread::makeName ( )
protected

Clears the thread's local storage.

◆ name()

std::string Poco::Thread::name ( ) const
inline

Returns the native thread ID of the thread.

Definition at line 300 of file Thread.h.

+ Here is the call graph for this function:

◆ operator=()

Thread & Poco::Thread::operator= ( const Thread & )
private

◆ setName()

void Poco::Thread::setName ( const std::string & name)

Returns the name of the thread.

◆ setOSPriority()

void Poco::Thread::setOSPriority ( int prio,
int policy = POLICY_DEFAULT )
inline

Returns the thread's priority.

Definition at line 340 of file Thread.h.

+ Here is the call graph for this function:

◆ setPriority()

void Poco::Thread::setPriority ( Priority prio)

Sets the name of the thread.

◆ setStackSize()

void Poco::Thread::setStackSize ( int size)
inline

Returns the maximum operating system-specific priority value, which can be passed to setOSPriority() for the given policy.

Definition at line 364 of file Thread.h.

+ Here is the call graph for this function:

◆ sleep()

void Poco::Thread::sleep ( long milliseconds)
inlinestatic

Wakes up the thread which is in the state of interruptible sleep. For threads that are not suspended, calling this function has the effect of preventing the subsequent trySleep() call to put thread in a suspended state.

Definition at line 322 of file Thread.h.

+ Here is the call graph for this function:

◆ start() [1/3]

void Poco::Thread::start ( Callable target,
void * pData = 0 )

Starts the thread with the given target.

The Thread ensures that the given target stays alive while the thread is running.

◆ start() [2/3]

void Poco::Thread::start ( Poco::SharedPtr< Runnable > pTarget)

Starts the thread with the given target.

Note that the given Runnable object must remain valid during the entire lifetime of the thread, as only a reference to it is stored internally.

◆ start() [3/3]

void Poco::Thread::start ( Runnable & target)

Returns the thread's stack size in bytes. If the default stack size is used, 0 is returned.

◆ startFunc() [1/2]

template<class Functor >
void Poco::Thread::startFunc ( const Functor & fn)
inline

Starts the thread with the given target and parameter.

Starts the thread with the given functor object or lambda.

Definition at line 157 of file Thread.h.

◆ startFunc() [2/2]

template<class Functor >
void Poco::Thread::startFunc ( Functor && fn)
inline

Starts the thread with the given functor object or lambda.

Definition at line 164 of file Thread.h.

◆ tid()

Thread::TID Poco::Thread::tid ( ) const
inline

Returns the unique thread ID of the thread.

Definition at line 288 of file Thread.h.

+ Here is the call graph for this function:

◆ tls()

ThreadLocalStorage & Poco::Thread::tls ( )
protected

Returns the native thread ID for the current thread.

◆ tryJoin()

bool Poco::Thread::tryJoin ( long milliseconds)

Waits for at most the given interval for the thread to complete. Throws a TimeoutException if the thread does not complete within the specified time interval.

◆ trySleep()

static bool Poco::Thread::trySleep ( long milliseconds)
static

Returns true if the thread is running.

◆ uniqueId()

static int Poco::Thread::uniqueId ( )
staticprotected

Creates a unique name for a thread.

◆ wakeUp()

void Poco::Thread::wakeUp ( )

Starts an interruptible sleep. When trySleep() is called, the thread will remain suspended until:

  • the timeout expires or
  • wakeUp() is called

Function returns true if sleep attempt was completed, false if sleep was interrupted by a wakeUp() call. A frequent scenario where trySleep()/wakeUp() pair of functions is useful is with threads spending most of the time idle, with periodic activity between the idle times; trying to sleep (as opposed to sleeping) allows immediate ending of idle thread from the outside.

The trySleep() and wakeUp() calls should be used with understanding that the suspended state is not a true sleep, but rather a state of waiting for an event, with timeout expiration. This makes order of calls significant; calling wakeUp() before calling trySleep() will prevent the next trySleep() call to actually suspend the thread (which, in some scenarios, may be desirable behavior).

◆ yield()

void Poco::Thread::yield ( )
inlinestatic

Suspends the current thread for the specified amount of time.

Definition at line 328 of file Thread.h.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ PooledThread

friend class PooledThread
friend

Definition at line 281 of file Thread.h.

◆ ThreadLocalStorage

friend class ThreadLocalStorage
friend

Definition at line 280 of file Thread.h.

Member Data Documentation

◆ _event

Event Poco::Thread::_event
private

Definition at line 277 of file Thread.h.

◆ _id

int Poco::Thread::_id
private

Definition at line 274 of file Thread.h.

◆ _mutex

FastMutex Poco::Thread::_mutex
mutableprivate

Definition at line 278 of file Thread.h.

◆ _name

std::string Poco::Thread::_name
private

Definition at line 275 of file Thread.h.

◆ _pTLS

ThreadLocalStorage* Poco::Thread::_pTLS
private

Definition at line 276 of file Thread.h.


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