Tutorial Lab 3 OS
Tutorial Lab 3 OS
c
Implement a function to initialize the context for a new thread by checking
resource availability, setting up memory, and configuring the thread’s starting
point. The function will set essential elements like the instruction and stack
pointers for the new thread.
This implementation ensures that each new thread starts with a properly
configured memory space, instruction pointer, and stack, ready to execute from
the specified entry point.
1
Goal of tcb init
Initialize the Thread Control Block (TCB) for all NUM IDS threads by:
• Setting each thread’s state to TSTATE DEAD.
• Initializing two indices to NUM IDS (representing NULL).
2
Goal of PTQueueInit.c
Implement functions to initialize and manage thread queues as doubly linked
lists based on indices. These queues should support operations like initialization,
insertion, removal, and retrieval.
2. Enqueue a Thread
• Obtain the current end of the queue.
• If the queue has existing elements:
– Link the current end to the new element by updating its next refer-
ence.
• If the queue is empty:
– Set the new element as the starting point of the queue.
• Update the new element’s previous reference and set it as the new end of
the queue.
3. Dequeue a Thread
• Identify the starting element of the queue.
• If the queue has no elements, return an indicator for an empty queue.
• If there are elements in the queue:
• Clear the connections of the removed element and return its identifier.
3
4. Remove a Specific Thread
• Retrieve the queue’s starting and ending elements as well as the elements
adjacent to the one being removed.
• If the element to remove is the starting element:
4
Goal of PThread.c
Develop functions for initializing the threading system, creating new threads,
and managing thread execution by yielding control between threads in a ready
queue.
5
Goal of TSyscallArg.c
Implement functions to manage system call arguments and return values within
a user context data structure. These functions facilitate communication between
the kernel and user processes, allowing system calls to access arguments and pass
results back to the calling process.
• For each function, identify the active process and update the correspond-
ing data entry to store the result that will be passed back to the user
process.
• These return values are stored in specific locations, allowing the calling
process to retrieve them after the system call concludes.
6
Goal of TSyscall.c
Implement system call functions that support user-space operations, specifically
focusing on spawning new processes and yielding control between processes.
Each function facilitates specific system call requests by managing resources
and interacting with process contexts.
7
Goal of TTrapHandler.c
Implement handlers to manage exceptions and interrupts that occur during
process execution. The exception handler function primarily addresses faults
such as page faults, while interrupt handler deals with system-generated inter-
rupts like timers or spurious interrupts, each directing control to appropriate
responses.
• For all other interrupts, apply a default handler that acknowledges the
interrupt and maintains system stability.
• This structure ensures that each interrupt type is directed to an appro-
priate handler, while other cases are managed consistently.