SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
Thread Class Reference

#include <Thread.h>

Public Types

enum  ActiveState { Activated, Stopped, NotActivated }
 Possible thread start states. More...
 

Public Member Functions

 Thread (Runnable *runner, const char *name, ThreadGroup *group=0, ActiveState state=Activated, unsigned long long stack_size=DEFAULT_STACKSIZE)
 
ThreadGroupgetThreadGroup ()
 Return the ThreadGroup associated with this thread. More...
 
RunnablegetRunnable ()
 Return the Runnable associated with this thread. More...
 
void setDaemon (bool to=true)
 
bool isDaemon () const
 Returns true if the thread is tagged as a daemon thread. More...
 
void activate (bool stopped)
 
void detach ()
 
bool isDetached () const
 Returns true if the thread is detached. More...
 
void setStackSize (unsigned long long stackSize)
 
unsigned long long getStackSize () const
 Returns the stack size for the thread. More...
 
void stop ()
 Stop the thread. More...
 
void resume ()
 Resume the thread. More...
 
void join ()
 
const char * getThreadName () const
 Returns the name of the thread. More...
 
void migrate (int proc)
 

Static Public Member Functions

static void exitAll (int code)
 Kill all threads and exit with code. More...
 
static void exit ()
 Exit the currently running thread. More...
 
static Threadself ()
 Returns a pointer to the currently running thread. More...
 
static int numProcessors ()
 Returns the number of processors on the system. More...
 
static ThreadGroupparallel (ParallelBase &helper, int nthreads, bool block, ThreadGroup *threadGroup=0)
 
template<class T >
static void parallel (T *ptr, void(T::*pmf)(int), int numThreads)
 
template<class T , class Arg1 >
static void parallel (T *ptr, void(T::*pmf)(int, Arg1), int numThreads, Arg1 a1)
 Another overloaded version of parallel that passes 1 argument. More...
 
template<class T , class Arg1 , class Arg2 >
static void parallel (T *ptr, void(T::*pmf)(int, Arg1, Arg2), int numThreads, Arg1 a1, Arg2 a2)
 Another overloaded version of parallel that passes 2 arguments. More...
 
template<class T , class Arg1 , class Arg2 , class Arg3 >
static void parallel (T *ptr, void(T::*pmf)(int, Arg1, Arg2, Arg3), int numThreads, Arg1 a1, Arg2 a2, Arg3 a3)
 Another overloaded version of parallel that passes 3 arguments. More...
 
template<class T , class Arg1 , class Arg2 , class Arg3 , class Arg4 >
static void parallel (T *ptr, void(T::*pmf)(int, Arg1, Arg2, Arg3, Arg4), int numThreads, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4)
 Another overloaded version of parallel that passes 4 arguments. More...
 
static void niceAbort (void *Context=0)
 
static int couldBlock (const char *why)
 
static void couldBlockDone (int restore)
 
static void yield ()
 The calling process voluntarily gives up time to another process. More...
 
static bool isInitialized ()
 
static void setDefaultAbortMode (const char *abortMode)
 
static void initialize ()
 

Friends

class Runnable
 
class ConditionVariable
 
class RecursiveMutex
 
class Mutex
 
struct Thread_private
 
class SystemCallManager
 
void Thread_run (Thread *t)
 
void Thread_shutdown (Thread *, bool)
 
void * run_threads (void *priv_v)
 
void handle_abort_signals (int, siginfo_t *, void *)
 
void handle_quit (int)
 
void handle_siguser2 (int)
 
void install_signal_handlers ()
 
void exit_handler ()
 

Detailed Description

The Thread class provides a new context in which to run. A single Runnable class is attached to a single Thread class, which are executed in another thread.

Member Enumeration Documentation

Possible thread start states.

Enumerator
Activated 
Stopped 
NotActivated 

Constructor & Destructor Documentation

Thread ( Runnable runner,
const char *  name,
ThreadGroup group = 0,
ActiveState  state = Activated,
unsigned long long  stack_size = DEFAULT_STACKSIZE 
)

Create a thread, which will execute the run() method in the runner object. The thread name is used for identification purposes, and does not need to be unique with respect to other threads. Group specifies the ThreadGroup that to which this thread should belong. If no group is specified (group==0), the default group is used.

Member Function Documentation

void activate ( bool  stopped)

If the thread is started in the the NotActivated state, use this to activate the thread (the argument should be false).

static int couldBlock ( const char *  why)
static

Mark a section as one that could block for debugging purposes. The int that is returned should be passed into couldBlockDone(int) when the section has completed. This will typically not be used outside of the thread implementation.

static void couldBlockDone ( int  restore)
static

Mark the end of a selection that could block. restore was returned from a previous invocation of the above couldBlock.

void detach ( )

Arrange to have the thread deleted automatically at exit. The pointer to the thread should not be used by any other threads once this has been called.

void exit ( )
static

Exit the currently running thread.

void exitAll ( int  code)
static

Kill all threads and exit with code.

Runnable* getRunnable ( )

Return the Runnable associated with this thread.

unsigned long long getStackSize ( ) const

Returns the stack size for the thread.

ThreadGroup* getThreadGroup ( )

Return the ThreadGroup associated with this thread.

const char* getThreadName ( ) const

Returns the name of the thread.

void initialize ( )
static
bool isDaemon ( ) const

Returns true if the thread is tagged as a daemon thread.

bool isDetached ( ) const

Returns true if the thread is detached.

static bool isInitialized ( )
static

Return true if the thread library has been initialized. This will typically not be used outside of the thread implementation.

void join ( )

Blocks the calling thread until this thead has finished executing. You cannot join detached threads or daemon threads.

void migrate ( int  proc)

Request that the thread migrate to processor proc. If proc is -1, then the thread is free to run anywhere.

static void niceAbort ( void *  Context = 0)
static

Abort the current thread, or the process. Prints a message on stderr, and the user may choose one of:

continue(c)/dbx(d)/cvd(v)/kill thread(k)/exit(e)

context is necesary on Windows to catch a segfault

int numProcessors ( )
static

Returns the number of processors on the system.

static ThreadGroup* parallel ( ParallelBase helper,
int  nthreads,
bool  block,
ThreadGroup threadGroup = 0 
)
static

Start up several threads that will run in parallel. A new ThreadGroup is created as a child of the optional parent. If block is true, then the caller will block until all of the threads return. Otherwise, the call will return immediately.

static void parallel ( T *  ptr,
void(T::*)(int)  pmf,
int  numThreads 
)
inlinestatic

Start up several threads that will run in parallel. If block is true, then the caller will block until all of the threads return. Otherwise, the call will return immediately.

static void parallel ( T *  ptr,
void(T::*)(int, Arg1)  pmf,
int  numThreads,
Arg1  a1 
)
inlinestatic

Another overloaded version of parallel that passes 1 argument.

static void parallel ( T *  ptr,
void(T::*)(int, Arg1, Arg2)  pmf,
int  numThreads,
Arg1  a1,
Arg2  a2 
)
inlinestatic

Another overloaded version of parallel that passes 2 arguments.

static void parallel ( T *  ptr,
void(T::*)(int, Arg1, Arg2, Arg3)  pmf,
int  numThreads,
Arg1  a1,
Arg2  a2,
Arg3  a3 
)
inlinestatic

Another overloaded version of parallel that passes 3 arguments.

static void parallel ( T *  ptr,
void(T::*)(int, Arg1, Arg2, Arg3, Arg4)  pmf,
int  numThreads,
Arg1  a1,
Arg2  a2,
Arg3  a3,
Arg4  a4 
)
inlinestatic

Another overloaded version of parallel that passes 4 arguments.

void resume ( )

Resume the thread.

Thread * self ( )
static

Returns a pointer to the currently running thread.

void setDaemon ( bool  to = true)

Flag the thread as a daemon thread. When all non-deamon threads exit, the program will exit.

static void setDefaultAbortMode ( const char *  abortMode)
static

set to "exit" (or something else) so we don't have to always wait for the user to input something

void setStackSize ( unsigned long long  stackSize)

Set the stack size for a particular thread. In order to use this thread, you must create the thread in the NotActivated state, set the stack size, and then start the thread using activate(false). Setting the stack size for a thread that is running or has ever been run, will throw an exception. The units are in bytes.

void stop ( )

Stop the thread.

void yield ( )
static

The calling process voluntarily gives up time to another process.

Friends And Related Function Documentation

friend class ConditionVariable
friend
void exit_handler ( )
friend
void handle_abort_signals ( int  sig,
siginfo_t *  info,
void *   
)
friend
void handle_quit ( int  sig)
friend
void handle_siguser2 ( int  )
friend

Make sure the exiting information is stored on the local stack In case we cannot access the structures any more

If not exiting tell we are running again

void install_signal_handlers ( )
friend
friend class Mutex
friend
friend class RecursiveMutex
friend
void* run_threads ( void *  priv_v)
friend
friend class Runnable
friend
friend class SystemCallManager
friend
friend struct Thread_private
friend
void Thread_run ( Thread t)
friend
void Thread_shutdown ( Thread thread,
bool   
)
friend

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