UCommon
ucommon::JoinableThread Class Referenceabstract

A child thread object that may be joined by parent. More...

#include <thread.h>

Inheritance diagram for ucommon::JoinableThread:
Collaboration diagram for ucommon::JoinableThread:

Public Member Functions

void background (void)
 Start execution of child context as background thread.
 
void start (int priority=0)
 Start execution of child context.
 
- Public Member Functions inherited from ucommon::Thread
virtual void exit (void)
 Exit the thread context.
 
bool isRunning (void) const
 
 operator bool () const
 
bool operator! () const
 
void setPriority (void)
 Set thread priority without disrupting scheduling if possible.
 
virtual ~Thread ()
 Destroy thread object, thread-specific data, and execution context.
 

Protected Member Functions

bool is_active (void) const
 Check if running.
 
void join (void)
 Join thread with parent.
 
 JoinableThread (size_t size=0)
 Create a joinable thread with a known context stack size.
 
virtual void run (void)=0
 Abstract interface for thread context run method.
 
virtual ~JoinableThread ()
 Delete child thread.
 
- Protected Member Functions inherited from ucommon::Thread
void map (void)
 Map thread for get method.
 
 Thread (size_t stack=0)
 Create a thread object that will have a preset stack size.
 

Protected Attributes

volatile bool joining
 
volatile bool running
 
- Protected Attributes inherited from ucommon::Thread
void * cancellor
 
int priority
 
enum ucommon::Thread:: { ... }  reserved
 
stacksize_t stack
 
pthread_t tid
 

Additional Inherited Members

- Static Public Member Functions inherited from ucommon::Thread
static size_t cache (void)
 Get cache line size.
 
static void concurrency (int level)
 Set concurrency level of process.
 
static bool equal (pthread_t thread1, pthread_t thread2)
 Determine if two thread identifiers refer to the same thread.
 
static Threadget (void)
 Get mapped thread object.
 
static void init (void)
 Used to initialize threading library.
 
static void policy (int polid)
 Used to specify scheduling policy for threads above priority "0".
 
static void release (void)
 
static pthread_t self (void)
 Get current thread id.
 
static void sleep (timeout_t timeout)
 Sleep current thread for a specified time period.
 
static void yield (void)
 Yield execution context of the current thread.
 
- Protected Types inherited from ucommon::Thread
enum  { R_UNUSED }
 

Detailed Description

A child thread object that may be joined by parent.

A child thread is a type of thread in which the parent thread (or process main thread) can then wait for the child thread to complete and then delete the child object. The parent thread can wait for the child thread to complete either by calling join, or performing a "delete" of the derived child object. In either case the parent thread will suspend execution until the child thread exits.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
Examples
thread.cpp.

Definition at line 823 of file thread.h.

Constructor & Destructor Documentation

◆ JoinableThread()

ucommon::JoinableThread::JoinableThread ( size_t size = 0)
protected

Create a joinable thread with a known context stack size.

Parameters
sizeof stack for thread context or 0 for default.

◆ ~JoinableThread()

virtual ucommon::JoinableThread::~JoinableThread ( )
protectedvirtual

Delete child thread.

Parent thread suspends until child thread run method completes or child thread calls it's exit method.

Member Function Documentation

◆ background()

void ucommon::JoinableThread::background ( void )
inline

Start execution of child context as background thread.

This is assumed to be off main thread, with a priority lowered by one.

Definition at line 875 of file thread.h.

◆ is_active()

bool ucommon::JoinableThread::is_active ( void ) const
protectedvirtual

Check if running.

Reimplemented from ucommon::Thread.

◆ join()

void ucommon::JoinableThread::join ( void )
protected

Join thread with parent.

Calling from a child thread to exit is now depreciated behavior and in the future will not be supported. Threads should always return through their run() method.

◆ run()

virtual void ucommon::JoinableThread::run ( void )
protectedpure virtual

Abstract interface for thread context run method.

Implements ucommon::Thread.

◆ start()

void ucommon::JoinableThread::start ( int priority = 0)

Start execution of child context.

This must be called after the child object is created (perhaps with "new") and before it can be joined. This method actually begins the new thread context, which then calls the object's run method. Optionally raise the priority of the thread when it starts under realtime priority.

Parameters
priorityof child thread.

Field Documentation

◆ joining

volatile bool ucommon::JoinableThread::joining
protected

Definition at line 834 of file thread.h.

◆ running

volatile bool ucommon::JoinableThread::running
protected

Definition at line 832 of file thread.h.


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