CSS 430
FAQ on Program 2: Scheduler
Q1:I want to run the lecture slide's Java code, but I don't know
how to transfer the files.
Q2: Should I run Test2.java and Test2b.java from my Shell.java?
A: No. Run those test programs from the loader
$ java boot
threadOS ver 1.0:
Type ? for help
threadOS: a new thread (thread=Thread[Thread-3,2,main] tid=0 pid=-1)
-->l Test2b
Q3: I modified the lecture slide's code (or the AOSJ textbook
example on pp160-161), renamed Scheduler.java, compiled it, and ran
ThreadOS. Then, I got the following error
goodall03 java Boot
threadOS ver 1.0:
Exception in thread "main" java.lang.NoSuchMethodError: Scheduler: method getMax
Threads()I not found
at Kernel.interrupt(Kernel.java:84)
at SysLib.boot(SysLib.java:15)
at Boot.main(Boot.java:10)
A: You have to modify ThreadOS' Scheduler.java. Don't rename the
slide/textbook example as Scheduler.
Q4: I got an error that Scheduler.getMaxThreads does not exist.
A: See the answer for Q3.
Q5: When I run a single instance of TestThread2, it seems like its
execution time took a double of what I expected:
[mfukuda@perseus kernel]$ java Boot
threadOS ver 1.0:
Type ? for help
threadOS: a new thread (thread=Thread[Thread-3,5,main] tid=0 pid=-1)
-->l TestThread2 a 2000
l TestThread2 a 2000
threadOS: a new thread (thread=Thread[Thread-6,5,main] tid=1 pid=0)
Thread[a]: response time = 936 turnaround time = 4976 execution time = 4040
-->
I thought that TestThreadb should be completed in 2 seconds.
A: Be reminded that ThreadOS Loader is regarded as one of user
threads.
Part 1:
--> l TestThread2 a 2000
0 1000 2000 3000 4000
Loader ---------- ----------
TestThread2 ---------- ----------
Q6: Java is still alive even terminating the main thread!
The round-robin scheduler shown in the lecture slide terminates the
TestScheduler.java main program while all the other spawned threads
are still working. I was taught that all child threads will be
terminated together when the main program/thread is terminated. What
happens to Java?
A: Java's actual main thread is Java Virtual Machine itself but
not your main program.
In C/C++, when your program starts from the main( ) function, the main
thread is in charge of executing your main( ) function. It can then
creates many child threads. If the main thread is terminated, all
child threads are also terminated. However, it does not happen to
Java. This is because the actual main thread is executing the Java
virtual machine itself! So, when your java program's main method is
executed, the virtual machine spawns a child thread and dedicate it to
your main method execution. Thus, even if your main method is
terminated, the java virtual machine can take care of the other child
threads.
As a matter of fact, our ThreadOS starts with the main( ) in Boot.java,
which is terminated as soon as it creates the Loader.java thread.
While Loader.java is alive, ThreadOS is working.
Q7: Are we permitted to make changes to other classes such as
TCB.java?
A: All you have to do is modify Scheduler.java only.
I recommend you should not change any other java files. However if you
want to change any other files or add new classes, you must send all
modified java files by email.
Q8: In part 2, what else should I change besides constructors and run( )?
A: You should modify getMyTcb( ) and addThread( ).
Q9: When the current thread is interrupted by another one with
higher priority, how should I resume it later?
If we have a thread called 'myThread' that is running in queue 2 and
is interrupted by a new thread in either queue 0 or queue 1, are we
supposed to continue to run 'myThread' from queue 2 the next time
queue 2 is able to run a thread. Or do we use queue.firstElement() to
get the next available thread in queue 2 and allow it to run.
A: You have to resume the suspended thread from the same queue for
the rest time quantum.
If we have a thread called 'myThread' that is running in queue 2 and
is interrupted by a new thread in either queue 0 or queue 1, you are
supposed to continue to run 'myThread' from queue 2 the next time
queue 2 is able to run a thread. You should not use queue.firstElement() to
get the next available thread in queue 2.
Q10: When I rename Part1's scheduler Scheduler1.java, should I also
rename the class name?
A: All you have to do is just change the file name into
Scheduler1.java