StuBS
Loading...
Searching...
No Matches
Thread Class Referenceabstract

The Thread is an object used by the scheduler. More...

#include <thread.h>

Inheritance diagram for Thread:
Collaboration diagram for Thread:

Public Member Functions

 Thread (void *tos)
 Constructor Initializes the context using prepareContext with the given stack space.
 
void go ()
 Activates the first thread on this CPU.
 
void resume (Thread *next)
 Switches from the currently running thread to the next one.
 
virtual void action ()=0
 Method that contains the thread's program code.
 

Public Attributes

volatile bool kill_flag
 Marker for a dying thread.
 

Static Protected Member Functions

static void kickoff (Thread *object)
 The thread's entry point.
 

Protected Attributes

Context context
 Context of the thread, used for saving and restoring the register values when context switching.
 

Private Attributes

Threadqueue_link
 pointer to the next element of the readylist
 

Friends

class Queue< Thread >
 
class Semaphore
 

Detailed Description

The Thread is an object used by the scheduler.

Constructor & Destructor Documentation

◆ Thread()

Thread::Thread ( void * tos)
explicit

Constructor Initializes the context using prepareContext with the given stack space.

Parameters
tosthe top of stack, highest address of some memory block that should be used as stack (remember stacks grow to the lower addresses on x86).

Member Function Documentation

◆ action()

void Thread::action ( )
pure virtual

Method that contains the thread's program code.

Derived classes are meant to override this method to provide meaningful code to be run in this thread.

Implemented in Application, IdleThread, and KeyboardApplication.

◆ go()

void Thread::go ( )

Activates the first thread on this CPU.

Calling the method starts the first thread on the calling CPU. From then on, Thread::resume() must be used for all subsequent context switches.

◆ kickoff()

void Thread::kickoff ( Thread * object)
staticprotected

The thread's entry point.

For the first activation of a thread, we need a "return address" pointing to a function that will take care of calling C++ virtual methods (e.g. action()), based on the thread object pointer. For this purpose, we use this kickoff() function.

Note
As this function is never actually called, but only executed by returning from the co-routine's initial stack, it may never return. Otherwise garbage values from the stack will be interpreted as return address and the system might crash.
Parameters
objectThread to be started

◆ resume()

void Thread::resume ( Thread * next)

Switches from the currently running thread to the next one.

The values currently present in the callee-saved registers will be stored in this threads context-structure, the corresponding values belonging to next thread will be loaded.

Parameters
nextPointer to the next thread.

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