MDAT
1.0
|
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... | |
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.
void ThreadManager::init | ( | int | numThreads, |
bool | useInteractive, | ||
bool | useSeed, | ||
unsigned int | seed | ||
) |
Initializes the thread manager.
[in] | numThreads | number of threads to track |
[in] | useInteractive | true: use interactive scheduling, false: use random scheduling |
[in] | useSeed | true: use specified seed, false: generate random seed based on time of day (ignored if useInteractive is true) |
[in] | seed | random 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.
[in] | id | id of thread |
[in] | property | property 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.
[in] | location | location 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.
[in] | id | id of thread to wait |
[in] | name | name of lock the thread is waiting on |
void ThreadManager::markWaitingOnSem | ( | int | id, |
string | name | ||
) |
Marks the thread as waiting on the specified semaphore.
[in] | id | id of thread to wait |
[in] | name | name 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.
[in] | waiting | queue of ids that can wakeup (must not be empty). |
void ThreadManager::updateSection | ( | string | section) |
Updates the section of the currently running thread.
[in] | section | name 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.