Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package osp.Threads; import java.util.Vector; import java.util.Enumeration; import osp.Utilities.*; import osp.IFLModules.*; import osp.Tasks.*; import osp.EventEngine.*; import osp.Hardware.*; import osp.Devices.*; import osp.Memory.*; import osp.Resources.*; /** This class

package osp.Threads; import java.util.Vector; import java.util.Enumeration; import osp.Utilities.*; import osp.IFLModules.*; import osp.Tasks.*; import osp.EventEngine.*; import osp.Hardware.*; import osp.Devices.*; import osp.Memory.*; import osp.Resources.*;

/** This class is responsible for actions related to threads, including creating, killing, dispatching, resuming, and suspending threads.

@OSPProject Threads */ public class ThreadCB extends IflThreadCB { /** The thread constructor. Must call

super();

as its first statement.

@OSPProject Threads */ public ThreadCB() { // your code goes here

}

/** This method will be called once at the beginning of the simulation. The student can set up static variables here. @OSPProject Threads */ public static void init() { // your code goes here

}

/** Sets up a new thread and adds it to the given task. The method must set the ready status and attempt to add thread to task. If the latter fails because there are already too many threads in this task, so does this method, otherwise, the thread is appended to the ready queue and dispatch() is called.

The priority of the thread can be set using the getPriority/setPriority methods. However, OSP itself doesn't care what the actual value of the priority is. These methods are just provided in case priority scheduling is required.

@return thread or null

@OSPProject Threads */ static public ThreadCB do_create(TaskCB task) { // your code goes here

}

/** Kills the specified thread.

The status must be set to ThreadKill, the thread must be removed from the task's list of threads and its pending IORBs must be purged from all device queues. If some thread was on the ready queue, it must removed, if the thread was running, the processor becomes idle, and dispatch() must be called to resume a waiting thread. @OSPProject Threads */ public void do_kill() { // your code goes here

}

/** Suspends the thread that is currenly on the processor on the specified event.

Note that the thread being suspended doesn't need to be running. It can also be waiting for completion of a pagefault and be suspended on the IORB that is bringing the page in. Thread's status must be changed to ThreadWaiting or higher, the processor set to idle, the thread must be in the right waiting queue, and dispatch() must be called to give CPU control to some other thread.

@param event - event on which to suspend this thread.

@OSPProject Threads */ public void do_suspend(Event event) { // your code goes here

}

/** Resumes the thread. Only a thread with the status ThreadWaiting or higher can be resumed. The status must be set to ThreadReady or decremented, respectively. A ready thread should be placed on the ready queue. @OSPProject Threads */ public void do_resume() { // your code goes here

}

/** Selects a thread from the run queue and dispatches it.

If there is just one theread ready to run, reschedule the thread currently on the processor.

In addition to setting the correct thread status it must update the PTBR. @return SUCCESS or FAILURE

@OSPProject Threads */ public static int do_dispatch() { // your code goes here

}

/** Called by OSP after printing an error message. The student can insert code here to print various tables and data structures in their state just after the error happened. The body can be left empty, if this feature is not used.

@OSPProject Threads */ public static void atError() { // your code goes here

}

/** Called by OSP after printing a warning message. The student can insert code here to print various tables and data structures in their state just after the warning happened. The body can be left empty, if this feature is not used. @OSPProject Threads */ public static void atWarning() { // your code goes here

}

/* Feel free to add methods/fields to improve the readability of your code */

}

/* Feel free to add local classes to improve the readability of your code */ image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions