AGENT++  4.0.3
Public Member Functions | Static Public Member Functions | Friends | List of all members
Thread Class Reference

A thread is a thread of execution in a program. More...

#include <threads.h>

Inheritance diagram for Thread:
Synchronized Runnable

Public Member Functions

 Thread ()
 Create a new thread.
 
 Thread (Runnable &r)
 Create a new thread which will execute the given Runnable.
 
virtual ~Thread ()
 Destroy thread.
 
virtual void run ()
 If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 
Runnableget_runnable ()
 Get the Runnable object used for thread execution.
 
void join ()
 Waits for this thread to die.
 
void start ()
 Causes this thread to begin execution; the system calls the run method of this thread.
 
void set_stack_size (long s)
 Before calling the start method this method can be used to change the stack size of the thread.
 
bool is_alive ()
 Check whether thread is alive.
 
Threadclone ()
 Clone this thread.
 
- Public Member Functions inherited from Synchronized
 Synchronized ()
 
 ~Synchronized ()
 
void wait ()
 Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
 
bool wait (unsigned long timeout)
 Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
 
void notify ()
 Wakes up a single thread that is waiting on this object's monitor.
 
void notify_all ()
 Wakes up all threads that are waiting on this object's monitor.
 
bool lock ()
 Enter a critical section.
 
TryLockResult trylock ()
 Try to enter a critical section.
 
bool unlock ()
 Leave a critical section.
 
- Public Member Functions inherited from Runnable
 Runnable ()
 
virtual ~Runnable ()
 

Static Public Member Functions

static void sleep (long millis)
 Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
 
static void sleep (long millis, int nanos)
 Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds.
 

Friends

class Synchronized
 
void * thread_starter (void *)
 

Additional Inherited Members

- Public Types inherited from Synchronized
enum  TryLockResult { LOCKED = 1, BUSY = 0, OWNED = -1 }
 

Detailed Description

A thread is a thread of execution in a program.

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started.

The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.

Author
Frank Fock
Version
3.5.7

Constructor & Destructor Documentation

Thread::Thread ( )

Create a new thread.

Thread::Thread ( Runnable r)

Create a new thread which will execute the given Runnable.

Parameters
runnablea Runnable subclass.
virtual Thread::~Thread ( )
virtual

Destroy thread.

If thread is running or has been finished but not joined yet, then join it.

Member Function Documentation

Thread* Thread::clone ( )
inline

Clone this thread.

This method must not be called on running threads.

Runnable& Thread::get_runnable ( )

Get the Runnable object used for thread execution.

Returns
a Runnable instance which is either the Thread itself when created through the default constructor or the Runnable object given at creation time.
bool Thread::is_alive ( )
inline

Check whether thread is alive.

Returns
Returns TRUE if the thread is running; otherwise FALSE.
void Thread::join ( )

Waits for this thread to die.

virtual void Thread::run ( )
virtual

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

Implements Runnable.

void Thread::set_stack_size ( long  s)
inline

Before calling the start method this method can be used to change the stack size of the thread.

Parameters
stackSizethe thread's stack size in bytes.
static void Thread::sleep ( long  millis)
static

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.

Parameters
millisnumber of milliseconds to sleep.
static void Thread::sleep ( long  millis,
int  nanos 
)
static

Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds.

Parameters
millisthe length of time to sleep in milliseconds.
nanos0-999999 additional nanoseconds to sleep.
void Thread::start ( )

Causes this thread to begin execution; the system calls the run method of this thread.

Friends And Related Function Documentation

friend class Synchronized
friend
void* thread_starter ( void *  )
friend

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