Thread Class Reference

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

#include <threads.h>

Inheritance diagram for Thread:

Synchronized Runnable

List of all members.

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.
boolean is_alive ()
 Check whether thread is alive.
Threadclone ()
 Clone this thread.

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 *)


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:
runnable a 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

static void Thread::sleep ( long  millis  )  [static]

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

Parameters:
millis number 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:
millis the length of time to sleep in milliseconds.
nanos 0-999999 additional nanoseconds to sleep.

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.

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.

void Thread::join (  ) 

Waits for this thread to die.

void Thread::start (  ) 

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

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:
stackSize the thread's stack size in bytes.

boolean Thread::is_alive (  )  [inline]

Check whether thread is alive.

Returns:
Returns TRUE if the thread is running; otherwise FALSE.

Thread* Thread::clone (  )  [inline]

Clone this thread.

This method must not be called on running threads.


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:

Generated on Fri May 29 22:36:56 2009 for AGENT++ by  doxygen 1.5.6