MDAT  1.0
 All Classes Files Functions Variables Typedefs Pages
ThreadManager Class Reference

thread manager More...

Public Member Functions

void init (int numThreads, bool useInteractive, bool useSeed, unsigned int seed)
 Initializes the thread manager. More...
 
void startThread (int id, string property)
 Starts a thread. More...
 
bool finishThread ()
 Mark the currently running thread as finished. More...
 
void invokeScheduler (int location=-1)
 Invokes the scheduler. More...
 
void markWaitingOnLock (int id, string name)
 Marks the thread as waiting on the specified lock. More...
 
void markWaitingOnSem (int id, string name)
 Marks the thread as waiting on the specified semaphore. More...
 
int wakeupThread (deque< int > &waiting)
 Selects a thread to wakeup from the specified waiting queue. More...
 
void updateSection (string section)
 Updates the section of the currently running thread. More...
 
int getCurrThreadId () const
 Returns the currently running thread. More...
 
string getThreadProperty (int id) const
 Returns the property string of the specified thread. More...
 
string getThreadTable () const
 Returns a table of all threads in a string. More...
 

Detailed Description

The thread manager is responsible for managing and scheduling the threads. Initially, the thread manager is initialized using init and each thread must call startThread to indicate they are starting the section of the program where MDAT takes control of the scheduling.

The thread manager contains the scheduler which is invoked using invokeScheduler. If interactive mode is used, the user will be prompted to enter the next thread to run. If random mode is used, the next thread is selected randomly. In either case, only threads that are eligible to run can be selected. Threads that are waiting or already selected cannot be run. If there is a case where no thread can run (and not all threads are completed), the program will abort with a deadlock.

The thread manager provides an interface to the lock and semaphore managers. These managers can mark a thread as waiting using the markWaitingOnLock or markWaitingOnSem methods. The wakeupThread method is also used by the lock and semaphore managers to permit the thread manager to wakeup a thread.

Member Function Documentation

void ThreadManager::init ( int  numThreads,
bool  useInteractive,
bool  useSeed,
unsigned int  seed 
)

Initializes the thread manager.

Parameters
[in]numThreadsnumber of threads to track
[in]useInteractivetrue: use interactive scheduling, false: use random scheduling
[in]useSeedtrue: use specified seed, false: generate random seed based on time of day (ignored if useInteractive is true)
[in]seedrandom seed (ignored if useInteractive is true or useSeed is false)
void ThreadManager::startThread ( int  id,
string  property 
)

First waits until all threads have been added. If the thread is the first one to run, it is set to run. Otherwise, the thread is paused.

Parameters
[in]idid of thread
[in]propertyproperty or type of thread
bool ThreadManager::finishThread ( )

Mark the currently running thread as completed. Returns true if it is last thread to finish and returns false otherwise.

void ThreadManager::invokeScheduler ( int  location = -1)

Invokes the scheduler, possibly causing a new thread to run. Aborts with a deadlock error if no threads are able to run.

Parameters
[in]locationlocation within source code - the currently running thread is updated with this location if the location is nonnegative (>= 0)
void ThreadManager::markWaitingOnLock ( int  id,
string  name 
)

Marks the thread as waiting on the specified lock.

Parameters
[in]idid of thread to wait
[in]namename of lock the thread is waiting on
void ThreadManager::markWaitingOnSem ( int  id,
string  name 
)

Marks the thread as waiting on the specified semaphore.

Parameters
[in]idid of thread to wait
[in]namename of semaphore the thread is waiting on
int ThreadManager::wakeupThread ( deque< int > &  waiting)

Selects a thread to wakeup from the specified waiting queue. The thread is removed from the waiting queue and placed on the ready queue. The method for selecting the thread is either done by the user (interactive scheduling) or randomly (random scheduling). Note this function does not change the thread that is currently running.

Parameters
[in]waitingqueue of ids that can wakeup (must not be empty).
void ThreadManager::updateSection ( string  section)

Updates the section of the currently running thread.

Parameters
[in]sectionname of new section
int ThreadManager::getCurrThreadId ( ) const

Returns the id of the currently running thread.

string ThreadManager::getThreadProperty ( int  id) const

Returns the property string associated with the specified thread.

string ThreadManager::getThreadTable ( ) const

Returns a table of all threads in a trace-friendly string.

This is a personal WEB site developed and maintained by an individual and not by Seattle University. The content and link(s) provided on this site do not represent or reflect the view(s) of Seattle University. The individual who authored this site is solely responsible for the site's content. This site and its author are subject to applicable University policies including the Computer Acceptable Use Policy (www.seattleu.edu/policies).