AttachedThread Class Reference

#include <Pt/System/Thread.h>

Thread that joins in its destructor. More...

Inherits Thread.

Public Types

enum  State {
  Ready = 0 ,
  Running = 1 ,
  Joined = 2 ,
  Detached = 3
}
 Status of a thread. More...

Public Member Functions

 AttachedThread ()
 Default Constructor.
 AttachedThread (const Callable< void > &cb)
 Constructs a thread with a thread entry.
 AttachedThread (EventLoop &loop)
 Constructs a thread with an event loop.
 ~AttachedThread ()
 Joins the thread, if not already joined.
void init (const Callable< void > &cb)
 Initialize with a thread entry.
State state () const
 Returns the current state of the thread.
void start ()
 Starts the thread.
void detach ()
 Detaches the thread.
void join ()
 Wait for the thread to finish execution.

Static Public Member Functions

static void exit ()
 Exits athread.
static void yield ()
 Yield CPU time.
static void sleep (unsigned int ms)
 Sleep for some time.

Detailed Description

AttachedThread is a Thread that calls join() when it is destroyed, unless join() already ran. The callable must outlive the thread.

Member Enumeration Documentation

◆ State

enum State
inherited
Enumerator
Ready 

Not started yet.

Running 

Thread is running.

Joined 

Joined with parent thread.

Detached 

Detached from parent thread.

Constructor & Destructor Documentation

◆ AttachedThread() [1/3]

AttachedThread ( )

Constructs a thread object without a thread entry. Use the init() method to set a callable.

◆ AttachedThread() [2/3]

AttachedThread ( const Callable< void > & cb)
explicit

Constructs a thread object to execute the Callable cb. The thread is not started on construction, but when start() is called.

◆ AttachedThread() [3/3]

AttachedThread ( EventLoop & loop)
explicit

Constructs a thread object to run the event loop loop in a separate thread. The thread is not started on construction, but when start() is called.

Member Function Documentation

◆ init()

void init ( const Callable< void > & cb)
inherited

The callable cb will be used as the thread entry. If another thread entry was set previously it will be replaced.

◆ start()

void start ( )
inherited

This starts the execution of the thread by calling the thread entry. Throws a SystemError on failure.

◆ exit()

void exit ( )
staticinherited

This function is meant to be called from within a thread to leave the thread at once. Implicitly called when the thread entry is left. Throws a SystemError on failure.

◆ yield()

void yield ( )
staticinherited

This function is meant to be called from within a thread to give up the CPU to other threads. Throws a SystemError on failure.

◆ sleep()

void sleep ( unsigned int ms)
staticinherited

The calling thread sleeps for ms milliseconds. Throws a SystemError on failure.