Keyple Util C++ Library 2.0.0
Reference Terminal Reader API for C++
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
keyple::core::util::cpp::Thread Class Referenceabstract

#include <Thread.h>

Classes

class  UncaughtExceptionHandler
 

Public Member Functions

 Thread (const std::string &name)
 
 Thread ()
 
virtual ~Thread ()=default
 
void setName (const std::string &name)
 
void start ()
 
void run ()
 
int join ()
 
bool isAlive ()
 
void interrupt ()
 
bool isInterrupted () const
 
std::string getName ()
 
void setUncaughtExceptionHandler (std::shared_ptr< UncaughtExceptionHandler > eh)
 

Static Public Member Functions

static void sleep (long millis)
 

Protected Attributes

bool mDone
 

Detailed Description

Definition at line 24 of file Thread.h.

Constructor & Destructor Documentation

◆ Thread() [1/2]

keyple::core::util::cpp::Thread::Thread ( const std::string &  name)
inline

Constructor

Allocates a new Thread object. This constructor has the same effect as Thread (null, null, name).

Parameters
namethe name of the new thread

Definition at line 39 of file Thread.h.

◆ Thread() [2/2]

keyple::core::util::cpp::Thread::Thread ( )
inline

Constructor

Allocates a new Thread object. This constructor has the same effect as Thread (null, null, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Definition at line 49 of file Thread.h.

◆ ~Thread()

virtual keyple::core::util::cpp::Thread::~Thread ( )
virtualdefault

Destructor

Member Function Documentation

◆ getName()

std::string keyple::core::util::cpp::Thread::getName ( )
inline

Definition at line 184 of file Thread.h.

◆ interrupt()

void keyple::core::util::cpp::Thread::interrupt ( )
inline

Interrupts this thread.

Unless the current thread is interrupting itself, which is always permitted, the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.

If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

If none of the previous conditions hold then this thread's interrupt status will be set.

Interrupting a thread that is not alive need not have any effect.

Exceptions
SecurityExceptionif the current thread cannot modify this thread

Definition at line 168 of file Thread.h.

◆ isAlive()

bool keyple::core::util::cpp::Thread::isAlive ( )
inline

Definition at line 116 of file Thread.h.

◆ isInterrupted()

bool keyple::core::util::cpp::Thread::isInterrupted ( ) const
inline

Definition at line 176 of file Thread.h.

◆ join()

int keyple::core::util::cpp::Thread::join ( )
inline

By default Pthreads are joinable. meaning you can wait for them to complete with a call to pthread_join(). The Thread class join method checks to see if the thread is running, then calls this function to wait for the thread to complete. If the call is successful the thread is marked as detached since pthread_join() automatically detatches a thread.

Definition at line 102 of file Thread.h.

◆ run()

void keyple::core::util::cpp::Thread::run ( )
inline

Definition at line 86 of file Thread.h.

◆ setName()

void keyple::core::util::cpp::Thread::setName ( const std::string &  name)
inline

Definition at line 59 of file Thread.h.

◆ setUncaughtExceptionHandler()

void keyple::core::util::cpp::Thread::setUncaughtExceptionHandler ( std::shared_ptr< UncaughtExceptionHandler eh)
inline

Definition at line 192 of file Thread.h.

◆ sleep()

static void keyple::core::util::cpp::Thread::sleep ( long  millis)
inlinestatic

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.

Parameters
millisthe length of time to sleep in milliseconds
Exceptions
IllegalArgumentExceptionif the value of millis is negative
InterruptedExceptionif any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown. static void sleep(long millis) throw(InterruptedException)

Definition at line 138 of file Thread.h.

◆ start()

void keyple::core::util::cpp::Thread::start ( )
inline

Causes this thread to begin execution.

The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).

It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

Exceptions
IllegalThreadStateExceptionif the thread was already started.

Definition at line 75 of file Thread.h.

Member Data Documentation

◆ mDone

bool keyple::core::util::cpp::Thread::mDone
protected

Definition at line 201 of file Thread.h.


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