Keyple C++
0.9.0
Keyple, an Open Source SDK for Ticketing
|
#include <Thread.h>
Public Member Functions | |
Thread () | |
Thread (const std::string &name) | |
virtual | ~Thread () |
void | start () |
int | join () |
int | detach () |
std::thread::id | selfId () |
std::thread * | self () |
void | setDaemon (bool on) |
void | interrupt () |
bool | isInterrupted () const |
virtual void * | run ()=0 |
std::string | getName () |
void | setThread (std::thread *t) |
Static Public Member Functions | |
static void | runThread (void *arg) |
static void | sleep (long millis) |
static std::thread::id | currentThreadId () |
Public Attributes | |
int | mAlive |
|
inline |
|
inline |
|
inlinevirtual |
Destructor
|
inlinestatic |
|
inline |
This is a utility method that detaches a thread when the caller doesn’t want to wait for the thread to complete. If the thread is running and not detached, pthread_detach() is called and the thread is flagged as detached if the call is successful.
|
inline |
|
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.
SecurityException | if the current thread cannot modify this thread |
|
inline |
|
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.
|
pure virtual |
|
inlinestatic |
In the call to pthread_create() the last argument is a void pointer to a data structure which will be passed to the runThread() function when it is called. Since the input argument to the runThread() is the Thread class this pointer, we can cast it to a Thread pointer then use it to call the Thread::run() method. Due to polymorphism, the Thread subclass run() method will be called to carry out the thread’s action.
|
inline |
|
inline |
This is another utility method that returns the thread ID for display or logging purposes.
|
inline |
|
inline |
|
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.
millis | the length of time to sleep in milliseconds |
IllegalArgumentException | if the value of millis is negative |
InterruptedException | if 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) |
|
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.
IllegalThreadStateException | if the thread was already started. |
int keyple::common::Thread::mAlive |